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

Re: bug or not? constants warn only once

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
April 25, 2008 03:17
Subject:
Re: bug or not? constants warn only once
Message ID:
20080425101739.GL79799@plum.flirble.org
On Thu, Apr 24, 2008 at 12:57:27PM -0500, David Nicol wrote:
> I think it does the right thing now and if directed to the relevant
> paragraph of perldoc I will attempt to submit a modification it
> making clear something to the effect that "Once a string has been
> evaluated as a number, it is considered to be numeric, for warning
> purposes, until it is loaded with a new string, at which time conversion
> to a number will be deferred until again needed."
> 
> go PMAW!

PMAW?

> On Thu, Apr 24, 2008 at 12:50 PM, Jan Dubois <jand@activestate.com> wrote:
> 
> > 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.
> >
> >  So you could say you should never cache if the conversion
> >  could have generated a warning.
> >
> >  Cheers,
> >  -Jan
> 
> that idea is so tail-wagging-the-dog.

It depends.

Why it surprised me was because I was trying to write a regression test, and
this code

for my $kapow (0..1) {

    ... # Lots of other code

    $SIG{__WARN__} = ...;

    func_under_test(..., "constant");

    ... # check the warnings

}

didn't do what I expected, because that constant string "constant" in the
optree isn't constant. Well, it can't be written to, but it gets conversions
cached on it.

I guess my expectation is that constants in the optree either are, or are not,
not some state in the middle where I can't change them from pristine, but the
internals can.

I wouldn't have been as surprised on $foo getting the warning only once.

Nicholas Clark

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