in reply to Re^2: Missing something with regards to references
in thread Missing something with regards to references

since I am always pathing through a reference, I apparently need to make a reference to the reference?

\$_[0] is not needed if the given (first) key is already a hashref. E.g.:

my %DATA = (3 => {}); put_element($DATA{3}, ...);

But it is needed if the key doesn't exist yet:

my %DATA = (3 => {}); put_element($DATA{42}, ...);

"But why doesn't my $current = \shift work? Why do I have to use my $current = \$_[0]?" Answer: If the key already exists and its value is a hashref, both possibilities work. But if the key does not exist, we have to make sure, that we really get a reference to the entry of %DATA, not the value of the non-existing entry.

sub test1 { my $val = shift; $val = 5; } sub test2 { $_[0] = 5; } my ($a, $b) = (3, 3); test1($a); # $a continues to be 3. test2($b); # $b is 5 now.

But I could have missed something, too.