@ARGV is an array, so you need to read the data as an array. One way is:

#!/usr/bin/perl -w # # input from command line # my ( $foo, $bar ) = @ARGV; print "foo = $foo\n"; print "bar = $bar\n";
You could also use $ARGV[0], 1, etc, and use $#ARGV to know how many arguments you have. Another way is just to use shift:
#!/usr/bin/perl -w # # input from command line # my $foo = shift; my $bar = shift; print "foo = $foo\n"; print "bar = $bar\n";
Now, if you're serious about command line input, I'd suggest looking at Getopt::Long. and perhaps Pod::Usage. A piece of the beginning of one of my work scripts might look like:

#!/usr/bin/perl # # embed perdoc somewhere (top or bottom) for script documentation. # use warnings; use strict; use Getopt::Long; use Pod::Usage; my $help = 0; my $man = 0; GetOptions('help|?' => \$help, man => \$man ) or pod2usage(2); pod2usage(-exitval => 0, -verbose => 1) if $help; pod2usage(-exitval => 0, -verbose => 2) if $man; my $file = shift; pod2usage(-exitfile => 1, -verbose => 1) unless ( defined( $file )); die("File $file is not a regular file.\n") unless ( -f $file );
Update: cleanup and typo fixes

In reply to Re: ARGV Usage by dwm042
in thread ARGV Usage by pp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.