Performance is different, and return hash ref has a much better performance. Try the following test: (I tried 1000 by 200, return hash cost 20 secs, when return ref only cost 13 secs. Well... you can see how slow my PC is.)
use strict;
sub return_hash {
my %hash;
for (0..shift) {
$hash{$_} = $_;
}
return %hash;
}
sub return_hash_ref {
my %hash;
for (0..shift) {
$hash{$_} = $_;
}
return \%hash;
}
my $ti = time();
for (0..$ARGV[1]) {
my %hash = return_hash($ARGV[0]);
}
print "return hash takes: ", time() - $ti, " secs\n";
$ti = time();
for (0..$ARGV[1]) {
my $hash = return_hash_ref($ARGV[0]);
}
print "return hash REF takes: ", time() - $ti, " secs\n";