develooper Front page | perl.perl5.porters | Postings from February 2011

Re: Bug with given() localization, pos() magic, and m//gc state

Thread Previous | Thread Next
From:
Father Chrysostomos
Date:
February 20, 2011 20:35
Subject:
Re: Bug with given() localization, pos() magic, and m//gc state
Message ID:
CF6C51A6-11B9-4A45-9DF4-94FC70B5C1AF@cpan.org

On Feb 20, 2011, at 7:22 PM, Eric Brine wrote:

> On Sun, Feb 20, 2011 at 6:45 PM, Father Chrysostomos <sprout@cpan.org> wrote:
> Tom Christiansen wrote:
> > (Tested on 5.13.9.)
> >
> > I can't figure out whether I've found a bug, or whether I'm being dense.
> > What happens is that if you do not manually reset the pos state when you
> > finally hit the end of the string, the next time through you are still at
> > the end.  Well, of course.  Right.
> >
> > But this happens when it is not the same variable anymore!  That is, it's
> > a new my variable that we're localizing via given().  It seems that the
> > pos() magic isn't getting reset when I feel that it should be.  Only when
> > you manually reset it do things get better, and no combination of my()
> > and local() makes any difference.
> 
> It *is* the same variable. given() re-uses the same lexical $_ (its own) each time.
> 
> given() doesn’t do any localisation or aliasing. ‘given($foo) { ++$_ }’ is a no-op.
> 
> So how come it doesn't act like an assignment when it comes to pos?
> 
> >perl -E"$_ = 'abc'; pos = 1; say pos//'u'; $_ = def; say pos//'u';"
> 1
> u

I don’t know. Maybe it is a bug, but I’ve already learnt more about given() than I’d like to know.


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