|
|
| Welcome to the Monastery | |
| PerlMonks |
Re: Benifits of using hash rather than number of variables?by DrHyde (Prior) |
| on Jul 20, 2011 at 10:11 UTC ( #915625=note: print w/ replies, xml ) | Need Help?? |
|
The three big advantages of passing hashes / hashrefs to your subroutines are:
The big disadvantage of using hashes is that you lose some strictness checking. use strict will usually tell you if you mis-type a variable name, but it can't tell you if you mis-type a hash key - instead, if you mis-type a key name when reading the hash, it'll just auto-vivify. This sort of bug can be a real pain in the arse to track down. Thankfully, there's a solution to this problem on the CPAN. Tie::Hash::Vivify is meant to let you provide "a hash where if you read a key that doesn't exist, it will call a code reference to fill that slot with a value", but it can of course be used thus:
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||