Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: hash undef?

by moritz (Cardinal)
on Nov 15, 2007 at 12:59 UTC ( [id://650966]=note: print w/replies, xml ) Need Help??


in reply to hash undef?

if (not defined $time{$recordNumber}){ ... }

You can also check with exists in hashes, the semantic is a little bit different.

Update: A bit explanation: == compares numbers, so in the expression $foo == undef the undef is promoted to 0 and compared with $foo - not what you want.

Replies are listed 'Best First'.
Re^2: hash undef?
by Anonymous Monk on Nov 15, 2007 at 15:16 UTC
    examples:

    perl -wMstrict -e "my %hash = (foo => 'x', bar => '', baz => undef); for (qw/foo bar baz quux/) { printf qq($_ exists:%s: $_ defined:%s: $_ true:%s: \n), exists($hash{$_}), defined($hash{$_}), $hash{$_} ? 1 : '' }" foo exists:1: foo defined:1: foo true:1: bar exists:1: bar defined:1: bar true:: baz exists:1: baz defined:: baz true:: quux exists:: quux defined:: quux true::
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-04-23 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found