print in a format of matrix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Magalhaes
    New Member
    • Jun 2008
    • 1

    print in a format of matrix

    Hi, i am starter in perl and I am having some problems, in the moment. I would like to know how broke this list in a format of matrix, for example..

    @list = 111111111111, whose have 12 elements in this format

    1 1 1 1
    1 1 1 1
    1 1 1 1

    with 3 lines and 4 columms.

    thanks.
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Originally posted by Magalhaes
    Hi, i am starter in perl and I am having some problems, in the moment. I would like to know how broke this list in a format of matrix, for example..

    @list = 111111111111, whose have 12 elements in this format

    1 1 1 1
    1 1 1 1
    1 1 1 1

    with 3 lines and 4 columms.

    thanks.
    One possibility:

    Code:
    use strict;
    use warnings;
    
    my @list = qw(1 1 1 1 1 1 1 1 1 1 1 1);
    
    for (@list) {
       for (1..4) {
          print shift @list;
       }
       print "\n";
    }
    Of course it is very contrived to fit your exact requirements.

    Comment

    Working...