Exists & Delete
- Use exists to find out if an element is in the hash
$hash{foo} = undef;
if ( exists $hash{foo} ) { print "yes\n" }
- Not the same as defined $hash{foo} !
- Use delete to delete a pair from a hash
delete $hash{foo}
| CPU: Perl, Fall 2005 | Perl, Week 4: More Arrays, Context, Subroutines, Lexical Variables | #52 |
$hash{foo} = undef;
if ( exists $hash{foo} ) { print "yes\n" }
delete $hash{foo}
| Copyright © 2005 Ian Langworth |