ambs has asked for the wisdom of the Perl Monks concerning the following question:
Hello.
What I really want (if the code worked as I was expecting):
sub create_f { my $func = shift; return sub { my $var = "xpto"; &$func; } } my $function = create_f( sub { print ">> $var <<\n" } );
I mean, supply a function that uses a variable that is declared outside. Of course I do not want this on this context, this is just my test code.
I do not want to make the variable global to the package.
Any hints?
Thanks! :)
Alberto Simões
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Making variables visible between calls.
by kennethk (Abbot) on Dec 12, 2008 at 18:24 UTC | |
Re: Making variables visible between calls.
by ikegami (Patriarch) on Dec 12, 2008 at 18:09 UTC | |
by ambs (Pilgrim) on Dec 12, 2008 at 18:12 UTC | |
by ikegami (Patriarch) on Dec 12, 2008 at 18:13 UTC | |
Re: Making variables visible between calls.
by kyle (Abbot) on Dec 12, 2008 at 18:15 UTC | |
Re: Making variables visible between calls.
by Arunbear (Prior) on Dec 12, 2008 at 18:31 UTC | |
Re: Making variables visible between calls.
by friedo (Prior) on Dec 12, 2008 at 18:12 UTC | |
Re: Making variables visible between calls.
by jeffa (Bishop) on Dec 12, 2008 at 18:06 UTC | |
by ambs (Pilgrim) on Dec 12, 2008 at 18:11 UTC | |
by eric256 (Parson) on Dec 12, 2008 at 20:13 UTC |
Back to
Seekers of Perl Wisdom