Programming Wiki: Using command line arguments in a Perl program

Programming Wiki : PerlCommandLineArguments

WikiHomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
Most recent edit on 2007-07-05 12:53:35 by MarkEdgar [revert accidental(?) deletion]

Additions:
$numArgs = $#ARGV + 1;

Deletions:
$numArgs = $#ARGV 1;



Edited on 2007-07-03 14:29:32 by Ly8Yh3

Additions:
$numArgs = $#ARGV 1;

Deletions:
$numArgs = $#ARGV + 1;



Edited on 2006-04-16 20:18:46 by ScottRippee

No differences.


Edited on 2006-04-16 19:29:25 by ScottRippee

No differences.


Oldest known version of this page was edited on 2006-04-16 19:27:03 by ScottRippee []
Page view:

Perl

Using command line arguments in a Perl program


Here's a simple program that prints the number of command-line arguments it's given, and the values of the arguments:
#!/usr/bin/perl
#---------------------#
#  PROGRAM:  argv.pl  #
#---------------------#

$numArgs = $#ARGV + 1;
print "thanks, you gave me $numArgs command-line arguments.\n";

foreach $argnum (0 .. $#ARGV) {

   print "$ARGV[$argnum]\n";

}


If you run this program from a Unix command-line like this

./argv.pl 1 2 3 4


or, from a DOS command-line like this

perl argv.pl 1 2 3 4


you'll get this result:

thanks, you gave me 4 command-line arguments.
1
2
3
4

Powered by Wikka Wakka Wiki 1.1.6.0
Page was generated in 0.0299 seconds