This is a discussion on How do I read command-line arguments with Perl? within the Perl forums, part of the Software Development category; Hi, How do I read command-line arguments with Perl? Thanks sivaraman,...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| hi, With Perl, command-line arguments are stored in the array named @ARGV. $ARGV[0] contains the first argument, $ARGV[1] contains the second argument, etc. $#ARGV is the subscript of the last element of the @ARGV array, so the number of arguments on the command line is $#ARGV + 1. 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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to read text area data line by line ? | KiruthikaSambandam | ASP and ASP.NET Programming | 3 | 01-23-2008 09:25 PM |
| Using PHP from Command Line | Sabari | PHP Programming | 4 | 12-18-2007 06:42 AM |
| How do I read command-line arguments with Perl? | leoraja8 | Perl | 3 | 11-26-2007 06:43 AM |
| How do I run a php script from the command line | itbarota | PHP Programming | 1 | 09-11-2007 03:06 AM |
| How do I access command-line arguments? | prasath | C and C++ Programming | 1 | 08-17-2007 11:46 PM |