a2p wrongly considers string literal "0" is always false
Bug #1062836 reported by
Ralph Corderoy
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
perl5 |
Unknown
|
Unknown
|
|||
perl (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Perl always considers a scalar with the string value "0" as false due to a scalar's polymorphism. awk does something similar, which is where Perl picked up the idea, but only if the string came from the user, e.g. an environment variable or read from a file. If the string is a constant in the source then it's true, not false. Perl's a2p(1) doesn't handle this subtlety.
$ printf '%s\n' '0 f' '1 t' | awk '$1 && "0"'
1 t
$ printf '%s\n' '0 f' '1 t' | perl -e "$(a2p <<<'$1 && "0"')"
$
$ a2p <<<'$1 && "0"' | grep print
print $_ if $Fld[1] && '0';
$
To post a comment you must log in.