Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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]
[ambrus]: No, you're not doing anything wrong. It's just that our automatic spam filters confuse you with the spammers who post advertisments for online shops of counterfeit branded clothing.
[ambrus]: Or unless you left the title field empty or entered a very short title for the node, but then you'd get a message saying that.
[ambrus]: I hope Corion or some other admin is here and can check the logs to see what the problem is.
[mz2255]: I wish I had an online shop but sadly no. The title field definitly wasn't short, had a perl module in the title with 5-6 additional words.
[ambrus]: you can also try to just post again in case it was some intermittent error

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2017-10-19 15:36 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (255 votes). Check out past polls.