No, they're not the same if $str
is "0"
.
You can simplify the statement by just checking the length:
if (length $str) { ...
In recent versions of Perl, length(undef)
is undef
without any warning generated. And using undef
as a boolean doesn't generate a warning either.
(By "recent" I mean 5.12 and up. Previously, length(undef)
would produce "Use of uninitialized value in length" if you have warnings turned on, which you should.)