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

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

by Codon (Friar)
on Sep 15, 2005 at 16:54 UTC ( #492329=note: print w/replies, xml ) Need Help??

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

Just know that string eval can be costly (starts a new Perl interpreter) and potentially dangerous (you aren't using tainted user input to build this string are you?; run this with perl -T to find out for sure).

Are you running this under use strict;? If so, then you will have some problems with my @returnsting. Specifically, you will need to have @returnstring declared before your eval to use it later. That means when you eval "my @returnstring = ...", you will create lexical variable within the scope of the eval that will mask the @returnstring that you declared outside of the eval scope. To solve this, simply remove the my from the string that you build.

Ivan Heffner
Sr. Software Engineer, DAS Lead, Inc.

Replies are listed 'Best First'.
Re^3: Probably an easy one - store command in variable.
by Joost (Canon) on Sep 15, 2005 at 16:58 UTC
    Just a nit-pick; string eval does not start a new perl interpreter, although it does need to compile the $string every time the eval statement is executed, which usually makes it slow compared to alternative strategies.

    There are also some subtle issues and bugs with eval $string and scoping, but you're unlikely to run into them if you use eval $string sparingly. update: as nobull states: in this particular case, you've ran into one such issue: a lexical variable declared inside a string eval is not available outside of the eval statement :-)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://492329]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2017-04-30 14:08 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (539 votes). Check out past polls.