http://www.perlmonks.org?node_id=450187


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.