Hi I was wondering what the most effective way of accomplishing the below would be. ( i know they accomplish the same thing but was wondering how most people would do this between the three, and WHY )
a.pl
my %hash = build_hash();
# do stuff with hash using $hash{$key}
sub build_hash
{ # build some hash
my %hash = ();
my @k = qw(hi bi no th xc ul 8e r);
for ( @k )
{
$hash{$k} = 1;
}
# RETURNS A COPY OF HASH?
return %hash;
}
b.pl
my $hashref = build_hash();
# do stuff with hash using $hashref->{$key}
sub build_hash
{ # build some hash
my %hash = ();
my @k = qw(hi bi no th xc ul 8e r);
for ( @k )
{
$hash{$k} = 1;
}
# just return reference (smaller than making copy?)
return \%hash;
}
c.pl
my %hash = %{build_hash()};
# do stuff with hash using $hash{$key}
# better because now we dont have to dreference our hashref each time using ->?
sub build_hash
{ # build some hash
my %hash = ();
my @k = qw(hi bi no th xc ul 8e r);
for ( @k )
{
$hash{$k} = 1;
}
return \%hash;
}