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


in reply to Re^7: Undefined vs empty string
in thread Undefined vs empty string

How does my defined-or solution compare on your system?

Where did I omit the empty string in

foreach $a (undef, "", 0, 1, "x" x 60) {

?

update new bench from your example. (my dor outperforms the other two consistently)

$ cat test.pl use strict; use Benchmark qw[ cmpthese ]; our @tests = ( (undef) x 1000, ("") x 1000, (chr(0)) x 1000, (0) x 1000, (1) x 1000, ("fred") x 1000, ); cmpthese -1, { a => q[ !(defined && length() ) and 1 for @tests; ], b => q[ !defined || $_ eq "" and 1 for @tests; ], c => q[ ($_ // "") eq "" and 1 for @tests; ], }; $ repeat 5 perl test.pl Rate b a c b 1950/s -- -18% -33% a 2379/s 22% -- -18% c 2901/s 49% 22% -- Rate b a c b 1950/s -- -22% -33% a 2511/s 29% -- -13% c 2901/s 49% 16% -- Rate b a c b 1950/s -- -23% -32% a 2536/s 30% -- -12% c 2875/s 47% 13% -- Rate b a c b 1914/s -- -22% -32% a 2466/s 29% -- -12% c 2801/s 46% 14% -- Rate b a c b 1950/s -- -23% -32% a 2536/s 30% -- -12% c 2875/s 47% 13% --

Enjoy, Have FUN! H.Merijn