Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Deleting hash entry

by broquaint (Abbot)
on Dec 16, 2003 at 15:05 UTC ( #315066=note: print w/replies, xml ) Need Help??


in reply to Deleting hash entry

Firstly, the first level of that hash assignment should be using parens and not curly braces. Now in answer to your first question, you will delete the def key in the hash pointed to by $hash{abc}. As for the second question, just test that the hash is empty with the use of keys in a scalar context e.g
use Data::Dumper; my %hash = ( abc => {}, ghi =>{ qw/ two key value pairs / } ); print "before: ", Dumper \%hash; delete $hash{abc} unless keys %{ $hash{abc} }; print "after: ", Dumper \%hash; __output__ before: $VAR1 = { 'abc' => {}, 'ghi' => { 'two' => 'key', 'value' => 'pairs' } }; after: $VAR1 = { 'ghi' => { 'two' => 'key', 'value' => 'pairs' } };
HTH

_________
broquaint

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://315066]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2018-06-19 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (114 votes). Check out past polls.

    Notices?