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

[perl #120047] perl should enable "$_" for use before calling subs

Thread Previous | Thread Next
From:
Linda Walsh via RT
Date:
September 30, 2013 03:30
Subject:
[perl #120047] perl should enable "$_" for use before calling subs
Message ID:
rt-3.6.HEAD-31239-1380511819-1283.120047-15-0@perl.org
On Sun Sep 29 18:06:51 2013, aristotle wrote:
> * Linda Walsh via RT <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?

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

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.






---
via perlbug:  queue: perl5 status: rejected
https://rt.perl.org:443/rt3/Ticket/Display.html?id=120047

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