You can't "return a hash" from a subroutine, you can only return a list, the effect of return %hash is to flatten the hash into a list of key => value pairs. Thus the effect of the the three following subroutines is similar (the order of the hash keys in the first aside:)
sub foo
{
my %foo = ( Foo => '1',
Bar => '2');
return %foo;
}
+
sub bar
{
my @bar = qw(Foo 1 Bar 2);
return @bar;
}
+
sub baz
{
return 'Foo','1','Bar','2';
}
+
print foo(),"\n";
print bar(),"\n";
print baz(),"\n";
This is why people are telling you to return a hash reference as this is the only way to retain the, er, hashiness after the appropriate dereferencing.
/J\ |