By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,712 Members | 1,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,712 IT Pros & Developers. It's quick & easy.

print in a format of matrix

P: 1
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.
Jun 24 '08 #1
Share this Question
Share on Google+
1 Reply


KevinADC
Expert 2.5K+
P: 4,059
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:

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3.  
  4. my @list = qw(1 1 1 1 1 1 1 1 1 1 1 1);
  5.  
  6. for (@list) {
  7.    for (1..4) {
  8.       print shift @list;
  9.    }
  10.    print "\n";
  11. }    
Of course it is very contrived to fit your exact requirements.
Jun 25 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.