Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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        

Comment on Re: undef-safe equality (shorter)
Download Code
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 chilling in the Monastery: (12)
As of 2016-05-24 10:47 GMT
Find Nodes?
    Voting Booth?