I have a subroutine which returns a reference to a hash. Trimming out the excess the code looks like
However, I'm concerned that each time the line
is run perl will need to effectively recreate %fullhash, which I expect to grow quite large. As an inexperienced perl coder this looks inefficient.
As an alterntive I'm looking at
As my test data is much smaller than the live data at the moment I can't do any direct timings. I would welcome any comments on which way to go.
Thanks
Ceci n'est pas une signature
Columb Healy
Code:
my %fullhash;
foreach my $val ( @arr )
{
my $hashref = dosubroutine ( $val );
%fullhash = ( %fullhash, %$hashref );
}
Code:
%fullhash = ( %fullhash, %$hashref );
As an alterntive I'm looking at
Code:
my %fullhash;
foreach my $val ( @arr )
{
my $hashref = dosubroutine ( $val );
foreach ( keys %$hashref )
{ $fullhash{$_} = $hashref->{$_}; }
}
Thanks
Ceci n'est pas une signature
Columb Healy