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

Re^4: Executing a string as a Perl command

by ctilmes (Priest)
on May 16, 2011 at 10:48 UTC ( #905040=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Executing a string as a Perl command
in thread Executing a string as a Perl command

This short illustrative example has $cmd set inline, but in a real program, it could be constructed from other variables, it could be read from a user, it could be read from a file, etc.

The question was simply how to get it to execute once it was set. The answer is eval.


Comment on Re^4: Executing a string as a Perl command
Replies are listed 'Best First'.
Re^5: Executing a string as a Perl command
by Anonymous Monk on May 16, 2011 at 11:01 UTC
    eval is the wrong answer since it can run arbitrary code

    If the user gives you some form of # rm -rf * ~ / , a lot of your files get deleted

      The OP said nothing about a user supplying the string. We pointed out that there are security concerns if you don't trust the string.

      If you want to run arbitrary code supplied by a 100% trusted source at runtime, what would you use other than eval?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (15)
As of 2015-07-30 16:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls