develooper Front page | perl.perl5.porters | Postings from February 2018

Re: [perl #132908] String/Number interpretation of a string

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
February 26, 2018 09:13
Subject:
Re: [perl #132908] String/Number interpretation of a string
Message ID:
20180226091241.GV3216@iabyn.com
On Sun, Feb 25, 2018 at 02:10:41PM -0800, James E Keenan via RT wrote:
> > perl -wlE '$_="-4-5"; $_+0; say -$_|0'
> > Useless use of addition (+) in void context at -e line 1.
> > Argument "-4-5" isn't numeric in addition (+) at -e line 1.
> > Argument "+4-5" isn't numeric in bitwise or (|) at -e line 1.
> > 4
> > 
> > perl -wlE '$_=-4 . -5; $_+0; say -$_|0'
> > Useless use of addition (+) in void context at -e line 1.
> > Argument "-4-5" isn't numeric in addition (+) at -e line 1.
> > 18446744073709551612

In the first example, $_="-4-5", $_ uses COW to share the string buffer
of the constant string; in $_=-4 . -5, the expression stops $_ being COW
(even though the expression is constant folded).

When the string is used in numeric context, its pIOK and pNOK
flags get set.

However, the result of the expression -$_ only has its pIOK and pNOK flags
set in the non-COW case.

I haven't looked any further yet at why that is.

-- 
Red sky at night - gerroff my land!
Red sky at morning - gerroff my land!
    -- old farmers' sayings #14

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About