Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Perl script parameters

by Amphiaraus (Acolyte)
on Oct 16, 2012 at 14:25 UTC ( #999343=perlquestion: print w/ replies, xml ) Need Help??
Amphiaraus has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to give a Perl script the following list of parameters? If so what syntax should be used?

1) The log file of a build, which is to be treated as an array of strings, and stored in an array variable. This is now working for me, I am using the syntax:

my @Build_Log_Array = <>;

2) In addition to the above parameter, I would also like my Perl script to take in three other parameters:

a) Build Version (a string)

b) Build Type (a string)

c) Build Attempt Number (an integer)

Comment on Perl script parameters
Download Code
Re: Perl script parameters
by kennethk (Monsignor) on Oct 16, 2012 at 14:50 UTC

    When I need to pass parameters, I use the CORE module Getopt::Long. The docs are pretty complete, and include type checking on input.

    Re: Log file, you could either feed it in on STDIN or pass the file name as a parameter and explicitly open (open my $fh, '<', $log or die "Open fail: $!";) and read (my @Build_Log_Array = <$fh>;) it. Both work, and which I use depends on the particulars of my need.


    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Re: Perl script parameters
by lune (Monk) on Oct 16, 2012 at 14:53 UTC

    Here's a link to an answer, that applies to you too:

    How do you use command line parameters?

    If you want your script to be maintainable, use parameter names, so you don't have to think about the ordering of your cli arguments and so on, I would really recommend using Getopt::Long. That way, you could write:

    myscript.pl --logfile /path/to/logfile --build_version 0.2 ...

Log In?
Username:
Password:

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

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

    The best computer themed movie is:











    Results (257 votes), past polls