[PLUG] Perl & command line arguments

patrick.n.fitzgerald.1 pfitzge1@purdue.edu
Thu, 9 Sep 1999 20:00:54 -0500 (EST)


On Thu, 9 Sep 1999, Jeff DeFouw wrote:

> On Thu, 9 Sep 1999, Fred Davis wrote:
> 
> > I have one question: Is it possible to get a Perl script to recognize
> > command line arguments (like $1, $2 in a shell script)? Or would I have to
> > add this functionality through a shell script that would call the Perl
> > script?

If all you need is the ability to act as a filter, utilizing standard
input or files given from the command line as input, you can use the
wonderful and mystic:

while(<>) {
   # parse a line, then print it out.
}

Or the even more wondrous and magical -n and -p command line options to
perl which put the above structure implicitly around your code. (-p also
adds a "print $_;" to the end of the while loop.)
Also, as I understand it, if you use pop(@ARGV) to pull command line
options off the array before starting the file mangling loop, you can have
a script that parses options as well as using the <> operator to
automagically go through all the remaining files on the command line. 

If you can buy, beg or borrow a Camel book, it will be of much help to
you. 

Cheers!
-Patrick
--
Gravity is a myth, the Earth sucks.
   --fortune (5)