Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Perl script parameters

by Amphiaraus (Beadle)
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)

Replies are listed 'Best First'.
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: --logfile /path/to/logfile --build_version 0.2 ...

Re: Perl script parameters
by kennethk (Abbot) 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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (8)
As of 2018-02-18 18:57 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (256 votes). Check out past polls.