in reply to Length of 2-dimensional array

Your question leaves room for interpretation. Move to strike. A fun answer, though certainly not your favorite (or useful?):
my $a; # a 2d-array my $count=0; for (@$a){ for (@$_){ $count++; } } print "My 2D-array is $count long\n";

Jeroen
"We are not alone"(FZ)

Replies are listed 'Best First'.
Re: Re: Length of 2-dimensional array
by c-era (Curate) on Apr 06, 2001 at 00:33 UTC
    This could also be written as:
    my $a; # a 2d-array my $count=0; for (@$a){ $count += $#$_+1; } print "My 2D-array is $count long\n";
      my $a = [[1,2,3],[4,5,6,7],[3]]; my $count = 0; $count += @$_ for @$a;

      --
      $you = new YOU;
      honk() if $you->love(perl)

      Yes. And extremely's reply spares even more keystrokes. Alls that inspires me to give a somewhat more useful answer:
      $a = [ [ 0..2 ], [0..10],[0..100] ]; my ($min, $max,$sum) = (undef, 0, 0); for (@$a){ $sum += my $a_length = @$_; $min = $a_length if $a_length < $min or not defined $min; $max = $a_length if $a_length > $max; } my $avg = $sum/ @$a; print "Avg: $avg; Min: $min; Max: $max\n";
      Gives some useful array statistics.

      Jeroen
      "We are not alone"(FZ)