
mhx
Enthusiast
/ Moderator
Jul 25, 2001, 9:48 PM
Post #5 of 6
(544 views)
|
Evaluating in scalar context works for multidimensional arrays as well, and saves you from keeping in mind that you have to add '1' all the time...
#!/bin/perl -w use strict; my @X = ( [1, 2], [3, 4], [5, 6], ); printf "Rows: %d\n", scalar @X; printf "Cols: %d\n", scalar @{$X[0]}; In a scalar assignment, you can even shorten this to
my $rows = @X; my $cols = @{$X[0]}; Of course, all this relies heavily upon the fact that all rows have the same number of columns. Since there are no 'real' multidimensional arrays in Perl as there are in C, you always have to keep in mind that you actually have an array of array references. Hope this helps. -- Marcus
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= ($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"
|