[Bug 1062836] [NEW] a2p wrongly considers string literal "0" is always false

Ralph Corderoy ralph at inputplus.co.uk
Sat Oct 6 13:14:08 UTC 2012


Public bug reported:

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';
    $

** Affects: perl (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to perl in Ubuntu.
https://bugs.launchpad.net/bugs/1062836

Title:
  a2p wrongly considers string literal "0" is always false

Status in “perl” package in Ubuntu:
  New

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 manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/perl/+bug/1062836/+subscriptions




More information about the foundations-bugs mailing list