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

Re: Probably an easy one - store command in variable.

by nobull (Friar)
on Sep 15, 2005 at 16:50 UTC ( [id://492327]=note: print w/replies, xml ) Need Help??


in reply to Probably an easy one - store command in variable.

The simple (and wrong) answer is, of course, eval.

Any variable declared within and eval(STRING) will go out of scope at the end of the eval().

Perhaps you should take a step back and say why you think that you want to do this.

I suspect the thing you are really looking for is the anonymous subroutine.

  • Comment on Re: Probably an easy one - store command in variable.

Replies are listed 'Best First'.
Re^2: Probably an easy one - store command in variable.
by Joost (Canon) on Sep 15, 2005 at 17:08 UTC
    expanding on the anonymous subroutine: you'd need something similar to this:
    my @list = qw(some random values); my $text = "bla bla bla"; my $command = sub { $d->checklist( text => $text, list => \@list ); }; my @returnlist = $command->();
    In this example $command is a closure - it "captures" the $text and @list variables. Depending on your problem that might or might not be the most elegant solution - without any context, it looks like you could also make a "normal" subroutine and pass those variables to it. YMMV.

Log In?
Username:
Password:

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

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

    No recent polls found