I'm guessing there is some coding design pattern with a best practice that wiser monks recognize here, and enlighten me : WWLD ? ( What would Larry do ?)use strict; my $href; fill_hashref ($href); print qq|TEST 1: $_\t$href->{$_}| for keys %$href; # Prints NOTHING my $empty_hash_href={}; fill_hashref ($empty_hash_href); print qq|TEST 2: $_\t$empty_hash_href->{$_}\n| for keys %$empty_hash_h +ref; # Works as expected sub fill_hashref{ my ($lref) = @_; $lref->{RETURNVALUE}="I would like to see this"; }
Update: Just to clarify - what I'm struggling with is that I occasionally forget to initialize the href passed in, and get bad results.
I am aware that an alternate solution is to use something like this in the sub:
But that has a certain ugliness (smell ?) to it, and was looking for a prettier, more aromatic solution.$_[0]->{WHATEVER}="blah";
While I am at it - how would this look/behave in perl6 ?
Syntactic sugar causes cancer of the semicolon. --Alan Perlis
In reply to Populating an undefined hashref in a sub by NetWallah
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |