faqts : Computers : Programming : Languages : Perl

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

76 of 92 people (83%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

Perl: Command: Line: Parameter: How to print all command line parameters?

Jul 10th, 2008 10:30
Knud van Eeden, Rich Pasco


----------------------------------------------------------------------
--- Knud van Eeden --- 25 December 2004 - 05:02 am -------------------
Perl: Command: Line: Parameter: How to print all command line 
parameters?
---
Use the $ARGV array, which contains by design all command line
parameters. It starts with 0, and ends at $#ARGV
===
Steps: Overview:
 1. -Create a Perl file (e.g. 'test.pl') containing text
     similar to the following
--- cut here: begin --------------------------------------------------
my $I = 0;
my $minI = 0;
my $maxI = $#ARGV;
#
for ( $I = $minI; $I <= $maxI; $I++ ) {
 print( "$ARGV[ $I ] \n" );
}
--- cut here: end ----------------------------------------------------
 2. -On the MSDos command line type the command
      perl <your perl filename> <your parameter1> <your parameter2> ...
     e.g.
      perl test.pl myparameter1 myparameter2 myparameter3
      shows the lines
       myparameter1
       myparameter2
       myparameter3
===
Internet: see also:
---
----------------------------------------------------------------------