in reply to Missing something with regards to references

Note that if you call put_element($DATA{3}, 'h', 'i', 'worked');, and $DATA{3} isn't a reference, the main datastructure will not be changed. I'd write the function like this:
sub put { die "Usage: put \\hash, key1, ..., keyn, value\n" unless @_ >= 3; my $hash = shift; die "Not a HASH reference\n" unless ref($hash) eq "HASH"; my $value = pop; my $key = pop; while (@_) { my $key = shift; if (!exists($hash->{$key})) { $hash = $hash->{$key} = { }; next; } elsif (ref($hash->{$key}) eq "HASH") { $hash = $hash->{$key}; next; } else { die "Not a HASH reference\n"; } } $hash->{$key} = $value; }
Make sure you always pass in a reference to the put function.