dave93 has asked for the wisdom of the Perl Monks concerning the following question:
In my code I frequently have to write conditions like this:
if (defined $string and $string ne "") { ..... }
What I really want is to check if the string is not entirely empty. I would like to be able to do something like if ($string) but this would exclude "0".
So I hope that there is a shorter and nicer way to do this. For now I have been using a utility strempty subroutine which runs that check but I doubt it's idiomatic.
In my own code I try to have it so that empty strings are simply undef, where applicable, but sometimes it can't be helped and external modules don't follow this rule hence why I have to write these conditions.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Checking string emptiness
by jwkrahn (Abbot) on Apr 04, 2025 at 22:09 UTC | |
by sleet (Monk) on Apr 04, 2025 at 22:23 UTC | |
by ikegami (Patriarch) on Apr 05, 2025 at 00:01 UTC | |
Re: Checking string emptiness
by dave93 (Acolyte) on Apr 05, 2025 at 00:01 UTC | |
Re: Checking string emptiness
by harangzsolt33 (Deacon) on Apr 06, 2025 at 04:13 UTC | |
by GrandFather (Saint) on Apr 06, 2025 at 21:25 UTC | |
|