Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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]
[Discipulus]: yes I know, bro' and I also know I cannot compete. But no one ask for oneliners.. ;=)
[Discipulus]: and i'm just happy for rising the black camel in the main ladderboard

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2017-10-22 20:20 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (275 votes). Check out past polls.