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

Enter Filename

by Anonymous Monk
on Jul 10, 2012 at 01:24 UTC ( #980798=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

What do I need to code to run my Perl Script from a command prompt like this:

perl myprogram.pl -i "C:\temp\inputfile.txt" -o "C:\temp\myoutput.csv" + -s "C:\temp\myoutput.stat"

Where the -i is the input file (required) and the -o is the output file location for a csv (required) and the -s is the output file for a .stat file (not required). I would like to be able to run all three or just two of these in one command line. I already have the code for the program but need to fiure out how to implement the arguments so that they can run in command line. Thank you

Comment on Enter Filename
Download Code
Re: Enter Filename
by monsoon (Pilgrim) on Jul 10, 2012 at 01:41 UTC
    Well, I think there were already enough hints and clues here Perl Input Parameters for Unix. If you were able to write the code that handles all that input, I'm pretty sure you can deal with the Getopt module no problem. Why not learn something new?
Re: Enter Filename
by NetWallah (Abbot) on Jul 10, 2012 at 02:30 UTC
    The "-s" option documented in "perlop perlrun" can help you parse and assign parameter values. This is useful for quick/dirty scripts.

    For maximum power/flexibility , use Getopt::Long.;

                 I hope life isn't a big joke, because I don't get it.
                       -SNL

Re: Enter Filename
by aitap (Deacon) on Jul 10, 2012 at 07:42 UTC
    You can use code from answers to your previous question and add a little check for the variable containing the value of -s parameter, something like this:
    defined $statfile && open my $FILE, ">", 'last_5min.stat' or die $!; <...> defined $statfile && print $FILE "<ED>$by</ED>\n<ECO>Max Busy</ECO>\n< +ECE></ECE>";
    Sorry if my advice was wrong.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2014-08-01 16:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (28 votes), past polls