Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: undef-safe equality (shorter)

by tye (Cardinal)
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        


Comment on Re: undef-safe equality (shorter)
Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2014-07-28 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (185 votes), past polls