Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

How do I completely remove a key/value pair from my hash?

by vroom (His Eminence)
on Mar 02, 2000 at 23:33 UTC ( [id://4685]=perlquestion: print w/replies, xml ) Need Help??

vroom has asked for the wisdom of the Perl Monks concerning the following question: (hashes)

How do I completely remove a key/value pair from my hash?

Originally posted as a Categorized Question.

  • Comment on How do I completely remove a key/value pair from my hash?

Replies are listed 'Best First'.
Re: How do I completely remove a key/value pair from a hash?
by vroom (His Eminence) on Jan 21, 2000 at 01:38 UTC
    use delete
    #Removes key and its associated value delete $hash{key}; #gets rid of a slice of key/value pairs at once; delete @hash {"first","second","third"};
Re: How do I completely remove a key/value pair from my hash?
by chromatic (Archbishop) on Mar 06, 2000 at 08:54 UTC
    Note that undef (Which many people try first) is the wrong answer. It only sets the value associated with a key to undef. That is usually not what you want:
    my %hash = ('one' => 'two', 'two' => '2'); undef $hash{'one'}; print keys %hash;
    This prints: twoone. Adding: print values %hash; prints: 2.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-23 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found