in reply to 2d array
Printing your 2D array is done much easier, less error prone and more "perlish" as follows (if you do not want to use the Data::Dump or Data::Dumper functions):use Modern::Perl; use Data::Dump qw /dd/; my @array_2d; push @array_2d, do {chomp; [split ',']} while (<DATA>); dd(@array_2d); __DATA__ 71,22,15,10,51 91,82,28,11,91 11,72,37,58,20 21,42,63,24,16 81,32,53,54,42
Actually your print routine contains an error: it only works because you have the same number of columns as rows! Do you spot your error?for my $row_ref (@array_2d) { for my $item (@$row_ref) { print "$item "; } print "\n"; }
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: 2d array
by jnarayan81 (Sexton) on Jan 04, 2013 at 12:22 UTC | |
by CountZero (Bishop) on Jan 05, 2013 at 09:02 UTC |