Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: undef-safe equality (shorter)

by tye (Sage)
on Apr 21, 2005 at 20:04 UTC ( #450187=note: print w/replies, xml ) Need Help??

in reply to undef-safe equality

Here's a shorter version (compared to the others I saw posted):

sub iseq { return defined($_[0]) == defined($_[1]) && $_[0] eq $_[1]; }

Update: Drat. You can't get away with that shortcut and still avoid the warning.

- tye        

Replies are listed 'Best First'.
Re^2: undef-safe equality (shorter)
by Roy Johnson (Monsignor) on Apr 21, 2005 at 22:11 UTC
    But you can do
    sub iseq { (!defined $_[0] || $_[0].9) eq (!defined $_[1] || $_[1].9); }
    Update - shorter:
    1 == keys %{{map {(!defined()||$_.9)=>1} @_}};

    Caution: Contents may have been coded under pressure.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2016-10-26 12:04 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (340 votes). Check out past polls.