Programming Wiki: Using command line arguments in a Perl program

Programming Wiki : PerlCommandLineArguments

WikiHomePage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Using command line arguments in a Perl program

Perl


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

There are no comments on this page. [Add comment]

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