In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/a5b92898b77edcbff06468ccf67150e50d1703e4?hp=b2a2a9010bb3413ad9c32e455d93e01069d0fd73>
- Log ----------------------------------------------------------------- commit a5b92898b77edcbff06468ccf67150e50d1703e4 Author: Renée Bäcker <renee.baec...@smart-websolutions.de> Date: Mon Oct 4 06:26:21 2010 -0700 [perl #57706] Unary minus on 'numeric' inputs like '-1' The attached patch adds the conversion if the value of the SV looks_like_number. ----------------------------------------------------------------------- Summary of changes: pp.c | 5 +++++ t/op/negate.t | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pp.c b/pp.c index 476212e..c478a47 100644 --- a/pp.c +++ b/pp.c @@ -2440,6 +2440,11 @@ PP(pp_negate) { SV * const sv = TOPs; const int flags = SvFLAGS(sv); + + if( looks_like_number( sv ) ){ + SvIV_please( sv ); + } + if ((flags & SVf_IOK) || ((flags & (SVp_IOK | SVp_NOK)) == SVp_IOK)) { /* It's publicly an integer, or privately an integer-not-float */ oops_its_an_int: diff --git a/t/op/negate.t b/t/op/negate.t index fb8d4b4..abe82bf 100644 --- a/t/op/negate.t +++ b/t/op/negate.t @@ -18,8 +18,8 @@ is(- -10, 10, "Simple numeric negation to positive"); is(-"10", -10, "Negation of a positive string to negative"); is(-"10.0", -10, "Negation of a positive decimal sting to negative"); is(-"10foo", -10, "Negation of a numeric-lead string returns negation of numeric"); -is(-"-10", "+10", 'Negation of string starting with "-" returns a string starting with "+" - numeric'); -is(-"-10.0", "+10.0", 'Negation of string starting with "-" returns a string starting with "+" - decimal'); +is(-"-10", 10, 'Negation of string starting with "-" returns a string starting with "+" - numeric'); +is(-"-10.0", 10.0, 'Negation of string starting with "-" returns a string starting with "+" - decimal'); is(-"-10foo", "+10foo", 'Negation of string starting with "-" returns a string starting with "+" - non-numeric'); is(-"xyz", "-xyz", 'Negation of a negative string adds "-" to the front'); is(-"-xyz", "+xyz", "Negation of a negative string to positive"); -- Perl5 Master Repository