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

reading commands from configuration file

by Sun751 (Beadle)
on Jul 03, 2009 at 01:27 UTC ( #776888=perlquestion: print w/replies, xml ) Need Help??
Sun751 has asked for the wisdom of the Perl Monks concerning the following question:

I am working on one project, where I am suppose to run list of commands copying, executingto achieve some target. And I am thinking of way to list all those commands in configuration file from where my script reads all of it in one hash as run it in sequential order one by one. And my question is, any one have any suggestion regarding this? Cheers
  • Comment on reading commands from configuration file

Replies are listed 'Best First'.
Re: reading commands from configuration file
by afoken (Monsignor) on Jul 03, 2009 at 08:39 UTC

    Sun751 prefers to create a new thread for each tiny aspect of the real problem.

    Su751, it would be easier to stay in one thread for the entire problem, this would give other monks more context to work with, and it would avoid repeated answers that don't help you. Of course, it would be helpful to explain the real problem.


    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Re: reading commands from configuration file
by belg4mit (Prior) on Jul 03, 2009 at 01:49 UTC
    You don't give us much to go by here, but I suspect do EXPR i.e; eval a file; might be a good place to start. As long as your commands are valid perl expression (including self-defined subroutines), it'll just work.

    In Bob We Trust, All Others Bring Data.

Re: reading commands from configuration file
by graff (Chancellor) on Jul 03, 2009 at 14:05 UTC
    As you should know from reading ikegami's reply on your other thread about this problem, if you want to run a set of commands "in sequential order one by one", you want these things in an array (or maybe an array of hashes, as ikegami suggested), not in a hash.

    Assuming that the sequence of commands does not involve anything that requires manual interaction by prompting for user input from "stdin", the easiest thing is to have the list of commands as plain text, one command per line, and execute each one in turn, in any of several ways.

    With unix/linux, this sort of text file is also known as a "shell script", which could just be executed on its own using the shell (e.g. source command_list.file or just  . command_list.file) -- no need for perl, really.

    Is there something you need to do that a simple shell script doesn't do for you?

Re: reading commands from configuration file
by Marshall (Abbot) on Jul 03, 2009 at 02:27 UTC
    It is not clear to me what you are trying to do. The most simple way to do this is a shell script or a .bat file if there are no decisions to be made.

    In general, I would recommend against putting any code that you run with eval{} into a config file. There can be very good reasons to do this, but until you understand what they are, DON'T do it. There can be big security holes with this and very unexpected results can result.

    There are a number of great Perl modules that can help with this. Can you give us say 5 lines of input and what you figure those 5 lines should do?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://776888]
Approved by ikegami
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2017-03-30 21:52 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (364 votes). Check out past polls.