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

[perl #3330] Magic increment avoids warning unexpectedly

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
May 23, 2012 14:55
Subject:
[perl #3330] Magic increment avoids warning unexpectedly
Message ID:
rt-3.6.HEAD-7788-1337810102-550.3330-15-0@perl.org
On Sat Jul 17 20:02:48 2010, greerga wrote:
> On Mon Jun 05 10:33:42 2000, clintp wrote:
> > This is a bug report for perl from clintp@geeksalad.org,
> > generated with the help of perlbug 1.26 running under perl 5.00503.
> > 
> > 
> > -----------------------------------------------------------------
> > [Please enter your report here]
> > 
> > 
> > The warning for "Argument X isn't numeric" is avoided even when
> > automagic increment doesn't happen because the arguments aren't
> > numeric.  Observe:
> > 
> > 
> > 	#!/usr/bin/perl -w
> > 
> > 	$m="a";
> > 	print ++$m;  # Prints "b", as expected
> > 
> > 
> > 	$m="a,b";
> > 	print $m+0;  # Prints 0, as expected
> > 		     # throws a warning also as expected
> > 
> > 
> > 	$m="a,b";
> > 	print ++$m;  # Prints 1, as expected
> > 		     # but throws no warning -- suprise?!?
> > 
> > I would have expected that since the automagic increment was avoided
> > in the third case that a warning should have been thrown that the
> > argument "a,b" wasn't numeric.
> > 
> > If the magic autoincrement happens, the warning should be supressed.
> > If it doesn't, the warning needs to be thrown.
> > 
> > This also occurs in 5.6 builds as well.
> 
> The most likely place to put this warning has a comment nearby that reads:
> 
>         /* Got to punt this as an integer if needs be, but we don't issue
>            warnings. Probably ought to make the sv_iv_please() that does
>            the conversion if possible, and silently.  */
> 
> so the lack of warning was intentional, probably due to atof() not being
> able to distinguish between non-numeric strings that result in 0 and
> strings like "0a" or ".0x" that legitimately result in 0.
> 
> As such, I'm not entirely convinced this patch is a good idea but it
> will at least be a point of discussion for whether to change the
> behavior or not.

I think it would be better to use looks_like_number to determine whether
to warn.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=3330

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