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

Re: bug or not? constants warn only once

Thread Previous | Thread Next
April 25, 2008 00:38
Re: bug or not? constants warn only once
Message ID:
(Quote from previous message)
> Not a bug. I recall relying on this behaviour somewhere to speed up
> loops. When you add 0 to a string value, it fills the IV/NV, so inside
> the loop it doesn't have to convert.

Do you recall how exactly you used it?

$foo = "abc";
$foo += 0;
$foo + 3;
==> This should warn once.

$foo= "abc";
$bar = $foo + 0;
$baz = $foo + 3;
==> This should warn twice.

> Also think dualvar. I use that, and I'd hate all my error messages to
> suddenly start warning in numeric context.

The way I see it with my - very, very - limited knowledge of the Perl  
If the numeric value is converted from the PV slot of an SV and  
contains other then numeric data ("pie", "12ab", ...)  then it should  
do what it does now but not set IOK flag.

For dualvars this wouldn't cause problems since there the IOK flag is  
set (which means the PV is never looked at).

In some situations it could be useful that it warns multiple times in  
other it might be annoying... (but there are problems to solve the  
annoying onces - adding += 0)

Consider a daemon for example... at the start of the code a scalar is  
set to a string instead of an int.
Assume that the scalar is used in a numeric context in the main loop  
of the daemon.
The first time it happens it will warns, the second time it will  
silently use 0. This could make it easy to miss the warning (and the  
problems it create).

Kind regards,


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About