1t Note: $#array is not the length, but the biggest index.
2nd note:use strict
#!/usr/bin/env perl
use strict;
my $ar1 = [1,2,3];
my $ar2 = [4,5,6,7];
my @arrays = ($ar1,$ar2);
foreach my $ary (@arrays) {
print $#{ary}, "\n";
}
__END__
Global symbol "@ary" requires explicit package name at test.pl line 10
+.
Execution of test.pl aborted due to compilation errors.
3d note: Read perldata and perlref! Really, that helps a lot!
4th note:
#!/usr/bin/env perl
use strict;
use warnings;
my $ar1 = [1,2,3];
my $ar2 = [4,5,6,7];
my @arrays = ($ar1,$ar2);
foreach my $ary (@arrays) {
# correct syntax
print $#{@$ary}, "\n";
# correct length
print scalar(@$ary), "\n";
}
regards,
tomte
Hlade's Law:
If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.
|