Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
more useful options
 
PerlMonks  

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

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

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 20, 2000 at 20: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 03: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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.