develooper Front page | perl.perl5.porters | Postings from July 2010

[perl #3330] Magic increment avoids warning unexpectedly

Thread Next
From:
George Greer via RT
Date:
July 18, 2010 13:46
Subject:
[perl #3330] Magic increment avoids warning unexpectedly
Message ID:
rt-3.6.HEAD-11314-1279422168-830.3330-15-0@perl.org
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.

-- 
George Greer


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