Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Is it better to return a hash of hashes or a reference to a hash of hashes?

by Juerd (Abbot)
on Mar 07, 2002 at 07:38 UTC ( [id://149962] : note . print w/replies, xml ) Need Help??


in reply to Is it better to return a hash of hashes or a reference to a hash of hashes?

One thing I'd like to add is that returning a hash reference allows for beatiful syntax when you're using a single element from it.
sub hash { qw(foo bar baz xyzzy) } sub hashref { return { qw(foo bar baz xyzzy) } } my %dummy = hash; $dummy = $dummy{foo}; # Afaik, there is no direct syntax to get a single element # but with hash refs, there is: $dummy = hashref->{foo} # equals $dummy = ${ hashref() }{foo}, which is ugly.
  • Comment on Re: Is it better to return a hash of hashes or a reference to a hash of hashes?
  • Download Code