in reply to size of an array of hash
&rien2rien(\@ut); . . . sub rien2rien { my $other = shift; for (my $i = 0; $i < @$other; $i++) { my $a = $other->[$i]{'first'}; my $b = $other->[$i]{'second'}; print "in other sub:\t$a\t$b\n"; } }
Other problems:
1) $a and $b have special meanings for sort. Using them as normal variables can cause unexpected problems. Use other names instead.
2) You're using prototypes (e.g. sub rien2rien(@)), which is a bad idea.
3) You use the ampersand notation for calling functions (e.g. &rien2rien(@ut) ) which overrides the prototype, also a bad idea.
4) You're using a C-style for loop, which is much less readable and no more efficient than a Perl-style for loop, or even a foreach loop:
sub rien2rien { my $other = shift; foreach (@$other) { my $var1 = $_->{'first'}; my $var2 = $_->{'second'}; print "in other sub:\t$var1\t$var2\n"; } }
|
|---|