Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
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


Comment on Re: Deleting hash entry
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://315066]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2014-12-21 04:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (102 votes), past polls