in reply to Making variables visible between calls.

How about just this?

my $function = sub { my $var = 'xpto'; print ">> $var <<\n" }; $function->();

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Making variables visible between calls.
by ambs (Pilgrim) on Dec 12, 2008 at 18:11 UTC

    That doesn't help. I need to let the user define his own function, and give him the possibility to access some pre-defined variables in case he wish to.

    My only possibility at the moment is to force the user defined function to receive a set of predefined parameters. But that will mess up some things later...

    But thanks, anyway ;)

    Alberto Simões

      It sounds like you realy want to pass it a hash. Then just preload the hash with values that it should have access to.

      my $function = sub {my $v = shift; print ">> $v->{var} <<\n" }; my $params = {var => 'exto'}; $function->($params);

      ___________
      Eric Hodges