in reply to Re^6: Undefined vs empty string
in thread Undefined vs empty string
I was actually kind of hoping that the example showed just that.
Here's an even mix of possible values including the empty string which you omitted, and the results are too close to call.:
#! perl -slw use strict; use Benchmark qw[ cmpthese ]; our @tests = ( (undef) x1000, ('') x1000, (chr(0)) x1000, (0) x1000, (1) x1000, ('fred') x1000, ); cmpthese -1, { a => q[ !(defined && length() ) and 1 for @tests; ], b => q[ !defined || $_ eq '' and 1 for @tests; ], }; __END__ C:\test>junk Rate b a b 1029/s -- -17% a 1239/s 20% -- C:\test>junk Rate b a b 1065/s -- -1% a 1079/s 1% --
Much of a muchness.
I guess you could get into varying the proportions of the mix commensurate with your application expectations, but ...
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Seekers of Perl Wisdom