Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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

by Aristotle (Chancellor)
on Oct 09, 2001 at 11:14 UTC ( [id://117661] : 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?

Another criterion to use is whether you are returning "final" or "intermittent" data: that is to say, if you just collected results in your subroutine (say, a DBI query), then returning a reference is probably the best idea most of the time. If, however, the data is a persistent part of an object, it is probably unwise to return a reference for several reasons. For one, you are giving your caller full access to the data; for another, some child class may choose to store data differently, so returning a hash reference is no longer a "natural" way to go about the query.