Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by Juerd (Abbot)
on Mar 06, 2002 at 18:42 UTC ( [id://149790] : 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 { { qw(foo bar baz xyzzy) } } my $dummy; # Using a single element only $dummy = ${ hash }{foo}; # UGLY! $dummy = hashref->{foo}; # Neat! # or hashref()->{foo} # or hashref->{'foo'} # etcetera.


But in the end, it's all up to you. Be sure to document your choise!

Originally posted as a Categorized Answer.

  • Comment on Re: Is it better to return an hash of hashes or a reference to an hash of hashes?
  • Download Code