in reply to add and delete to hash reference

this is why it's a VERY good idea to use strict:

(also note that it's a good idea to post self-contained code for relatively simple problems like this).

use strict; my $key; print "create hashref\n"; my $closurehash = { some_key => { name => 'fake35' } }; foreach $key ( keys(%{$closurehash}) ) { print "$closurehash->{$key}->{'name'}\n"; } print "add to hashref\n"; $closurehash->{ "test" } = "test"; # hash ref foreach $key ( keys(%{$closurehash}) ) { print "$closurehash->{$key}->{'name'}\n"; } print "delete from hashref\n"; delete $closurehash->{"fake35"}; foreach $key ( keys(%{$closurehash}) ) { print "$closurehash->{$key}->{'name'}\n"; }
output:
create hashref fake35 add to hashref Can't use string ("test") as a HASH ref while "strict refs" in use at +test.pl line 12.
In other words, "test" is NOT a hash ref. Or if it is, it's a symbolic reference to some hash called "test" that isn't mentioned in your code.

If you use a real hash-ref like so:

$closurehash->{ "test" } = { name => "test"}; # hash ref
it'll work as expected.