You can use Data::Dumper to assure yourself that delete is working.
use Data::Dumper;
my $var = { '1234-567' => { 'key1' => 'stuff' ,
'key2' => 'stuff',
},
'1234-997' => { 'key1' => 'stuff' ,
'key2' => 'stuff',
}
};
print Dumper($var);
delete $var->{'1234-997'};
print Dumper($var);
produces
$VAR1 = {
'1234-567' => {
'key2' => 'stuff',
'key1' => 'stuff'
},
'1234-997' => {
'key2' => 'stuff',
'key1' => 'stuff'
}
};
$VAR1 = {
'1234-567' => {
'key2' => 'stuff',
'key1' => 'stuff'
}
};
You're getting bitten by the fact if $var->{a} doesn't exists, then tests on $var->{a}->{b} will autovivify $var->{a} (though the same test on $var->{a} wouldn't.)
my $var = {};
print if exists $var->{a};
print Dumper($var);
print if exists $var->{a}->{b};
print Dumper($var);
produces
$VAR1 = {};
$VAR1 = {
'a' => {}
};