develooper Front page | perl.perl5.porters | Postings from June 2012

[perl #57706] Unary minus on 'numeric' inputs like '-1'

Thread Previous
From:
Father Chrysostomos via RT
Date:
June 7, 2012 08:37
Subject:
[perl #57706] Unary minus on 'numeric' inputs like '-1'
Message ID:
rt-3.6.HEAD-5009-1339083435-741.57706-14-0@perl.org
On Mon Oct 04 08:43:03 2010, sprout wrote:
> On Mon Nov 10 07:34:21 2008, renee.baecker@smart-websolutions.de wrote:
> > Hi,
> > 
> > > % perl -E 'say -"-1"'
> > > +1
> > > % perl -E 'say - -1'
> > > 1
> > > % perl -E 'say 0 - "-1"'
> > > 1
> > >
> > > [...]
> > >
> > > I would expect to see
> > >
> > > % perl -E 'say - -1'
> > > 1
> > > % perl -E 'say -"-1"'
> > > 1
> > > % perl -E 'say -"-foo"'
> > > +foo
> > >
> > > To me, that matches the documentation better than the current
> > behaviour.
> > 
> > The documentation is a bit inconsistent:
> > 
> > perlop says "Otherwise, if the string starts with a plus or minus, a
> > string starting with the opposite sign is returned."
> > 
> > Your first example is a string. So the current behaviour seems to be
> > correct.
> > 
> > OTOH, perlnumber says "The binary operators +  -  *  / %  ==  !=  > < >=
> >  <=  and the unary operators -  abs and --  will attempt to convert
> > arguments to integers"
> > 
> > ...
> > 
> > The attached patch adds the conversion if the value of the SV
> > looks_like_number...
> 
> Thank you. Applied as a5b92898b77edcbff.

Except that patch did not take magic variables into account.

However, no numeric ops fully accounted for those.

This is now fixed for magic variables in e38171cf57f, which relies on
changes made in 01f91bf2755, two commits earlier.

> 
> > Nevertheless, the documentation should be fixed, no matter what
> > behaviour is "correct".
> 
> I tweaked the perlop description in commit da2f94c54905.


-- 

Father Chrysostomos


Thread Previous


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