andrewkl has asked for the wisdom of the Perl Monks concerning the following question:
////////////////////////////////////////////////////////////////////////////sub foo { my @arr = (); my %hash = (); .... %hash = .... # key/values populated by some API push(@arr, \%hash); bar(\@arr, <other_args>); # @arr contains only one item } sub bar { my $array_ref = shift; .... other function args are accessed here foreach my $i (.....) { .... %some_hash initialized here for each iteration of the for +-loop push (@$array_ref, \%some_hash); } zzz($array_ref); # zzz() will do some read-only operations with +this array }
sub foo { my %hash = (); .... %hash = .... # key/values populated by some API bar(\%hash, <other_args>); # <<<----- Is this better/best practi +ce compared to Scenario 1 ? } sub bar { my $hash_ref = shift; .... other function args are accessed here my @array = (); push (@array, $hash_ref); foreach my $i (.....) { .... %some_hash initialized here for each iteration of the for +-loop push (@array, \%some_hash); } zzz(\@array); # zzz() will do some read-only operations with this + array }
|
|---|