in reply to Re: passing multi dimensional hashes into a sub
in thread passing multi dimensional hashes into a sub

the reason I asked previously about hash format was to try to understand when %hash should be used rather than %hash_ref ($hash_ref->{$key})

when wrongly used, I get an error that reads Global explicit package... and need to declare it...I seem to get a lot so i need to understand where to use one or the other

ergo, the reason why I asked for you to explain how you go about deciding which to use %hash vs %hash_ref...hoping to get some insight into this!

yes, I've read up on this subject and still confused

  • Comment on Re^2: passing multi dimensional hashes into a sub

Replies are listed 'Best First'.
Re^3: passing multi dimensional hashes into a sub (when to use a hash or vs hashref )
by Anonymous Monk on Sep 18, 2015 at 00:17 UTC

    Never use %hash_ref, its not a "ref"erence, its a hash, so don't call it a reference

    Also never use %hash either, the % part tells you its a hash, the "hash" part is supposed to describe whats inside this dictionary, which "hash" doesn't do

    Outside of an introduction to hashes never use hash unless you're storing md5sum or some such, in which case you still shouldn't use it, unless the type of hash isn't set (can be md5 or sha1 or ... so the generic hash fits)

    See age of peter, sum of bob and Subroutines: Returning a hash vs. hash reference and free book Modern Perl

    So taking all this into account

    Do you see when you would use it %Scores versus $ScoresRef?

    So, we use hash references to save memory,

    and we use hashes to avoid typing  ->

    once you get used to the idea of typing  -> , you use hashes to avoid scaring noobs :)