On Thu, 24 Apr 2008, Nicholas Clark wrote: > On Thu, Apr 24, 2008 at 07:23:50PM +0200, H.Merijn Brand wrote: > > > > The implementation caches the numeric result, and uses that next time round, > > > before it gets a chance to warn. It's been this way since (at least) 5.005_03 > > > (which is the oldest perl I have hanging around) > > > > > > So is this a bug? Advice from Klortho #11943 suggests not: > > > > 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. > > Oh, I didn't mean that the caching was a bug. No, caching is key. > I meant that not warning felt buggy. > > Although, this is a simpler example: > > $ ./perl -lwe '$a = "Pie"; print 0 + $a; print 0 + $a' > Argument "Pie" isn't numeric in addition (+) at -e line 1. > 0 > 0 I was tempted to argue that caching shouldn't happen if the conversion generated a warning. But that gets confusing, because once you use the non-number as a number in a context that has warnings disabled, then you magically aquire the IOKp flag and you'll stop warning even in warning contexts. So you could say you should never cache if the conversion could have generated a warning. Cheers, -JanThread Previous | Thread Next