Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Local for lexicals

by mzedeler (Pilgrim)
on Aug 10, 2009 at 14:58 UTC ( [id://787349]=note: print w/replies, xml ) Need Help??


in reply to Local for lexicals

Maybe something like this?

our $x = 1; my $f = sub { $x }; { local $x; $x = 2; print $f->(), "\n"; } print $f->(), "\n";

It doesn't give you a way to make my-declared variables local, though.

Replies are listed 'Best First'.
Re^2: Local for lexicals
by JadeNB (Chaplain) on Aug 10, 2009 at 15:44 UTC
    (I thought I posted this already, but it doesn't seem to have appeared. Let's see if I get two dups in a single thread!)

    Thanks for the suggestion, but, unfortunately, it's only the bit in the inner scope that I control—given an existing coderef $f that closes over an existing lexical $x, I want to write some code that changes $x, but only temporarily, in such a way that $f ‘sees’ the change.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://787349]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found