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

[perl #3330] Magic increment avoids warning unexpectedly

Thread Previous
From:
Father Chrysostomos via RT
Date:
April 20, 2012 22:36
Subject:
[perl #3330] Magic increment avoids warning unexpectedly
Message ID:
rt-3.6.HEAD-4610-1334986585-288.3330-15-0@perl.org
On Fri Apr 20 18:18:24 2012, jkeenan wrote:
> 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.
> > > 
> > > 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.
> > 
> 
> Still true in Perl 5.14.2:
> 
> #####
> 
> $ perl -wE '$m="a";say ++$m;'
> b
> 
> $ perl -wE '$m="a,b";say $m+0;'
> Argument "a,b" isn't numeric in addition (+) at -e line 1.
> 0
> 
> $ perl -wE '$m="a,b";say ++$m;'
> 1
> 
> #####
> 
> [snip]
> 
> > 
> > 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.
> 
> Was there any further consideration of this patch or the problem it
> addressed?

I don’t actually understand that part of the code, but I’ve added it to
my own list of about 20 patches to consider after 5.16.

-- 

Father Chrysostomos


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

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