develooper Front page | perl.perl5.porters | Postings from September 2013

Re: [perl #120047] perl should enable "$_" for use before callingsubs

Thread Previous | Thread Next
From:
pagaltzis
Date:
September 30, 2013 12:59
Subject:
Re: [perl #120047] perl should enable "$_" for use before callingsubs
Message ID:
20130930125930.GA21434@fernweh.plasmasturm.org
* lindaw <perlbug-followup@perl.org> [2013-09-30 05:35]:
> On Sun Sep 29 18:06:51 2013, aristotle wrote:
> > * lindaw <perlbug-followup@perl.org> [2013-09-30 02:20]:
> > > if I have:
> > >
> > > sub reader() {
> > >   my save=$_";
> > >   open(my $fh, "<myfile") or die "open:$!";
> > >   while (<$fh>) {
> > >   ...
> > >   }
> > >   $_=$save;
> > > }
> >
> > Yes if you have that, you change the `my $save = $_` to `local $_`
> > and you drop the last line.
>
> So when I split the routine in two with a goto &end, how will the $_
> being transported to the end of the routine?

I don’t know, how will the lexical variable be transported?

> It won't because local's are not popped when the call stack pops, they
> are popped on branches as well.

Neither will $save.

> That's why my first approach was something perhaps more general about
> having local vars survive over a goto, as it isn't at all intuitive
> that a lateral branch would really be a context pop that one would
> expect to come when one returns.

Yes, perhaps. Your approach makes many more assumptions about $_ than
localising would and does not even do what you claim, but maybe there
exists some sense in which it is more general.

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