Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Making variables visible between calls.

by jeffa (Bishop)
on Dec 12, 2008 at 18:06 UTC ( [id://730000]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-19 06:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found