Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Making variables visible between calls.

by ikegami (Patriarch)
on Dec 12, 2008 at 18:09 UTC ( [id://730002]=note: print w/replies, xml ) Need Help??


in reply to Making variables visible between calls.

sub create_f { my $func = shift; return sub { $func->("xpto"); } } my $function = create_f( sub { my $var = shift; print ">> $var <<\n" } );

It's technically possible using dynamic scoping (local), but that increases coupling. What I presented is a much better alternative.

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

    Yes, at the moment that is my own solution, but that forces the user to get a set of predefined parameters. It works, but not as clean as I would like it to be to the user. ;)

    Thanks

    Alberto Simões

      A set? No. You could pass a hash or an object.

      Not as clean? Any method of passing arguments without using parameters would be less clean than using parameters.

Log In?
Username:
Password:

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

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

    No recent polls found