in reply to Checking string emptiness

There are a few other ways too...

sub isEmpty { return defined $_[0] ? !length($_[0]) : 1; }


sub isEmpty { defined $_[0] or return 1; return !($_[0] =~ tr|||c); }


sub isEmpty { return !(defined $_[0] && $_[0] =~ m/./); }

Replies are listed 'Best First'.
Re^2: Checking string emptiness
by GrandFather (Saint) on Apr 06, 2025 at 21:25 UTC

    Why try to obfuscate it? Just use if (length $string) { as suggested by jwkrahn?

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
    A reply falls below the community's threshold of quality. You may see it by logging in.