On Jun 19, 4:55 pm, [EMAIL PROTECTED] (Rajnikant) wrote: > Hope this snipet will help you :). > > # Use :Perl -w test_argc.pl --name Irfan > > use strict; > use warnings; > > # Get args > my @argv = @ARGV; > > #get args cnt > my $argc = @ARGV; > > my $icnt = 0; > > if($argc != 0) > { > for($icnt = 0;$icnt < $argc;$icnt++) > { > if($argv[$icnt] eq "--name") > { > print (" Name is $argv[$icnt+1] \n"); > $icnt++; > } > }} > > else > { > print ("USAGE: script_name --name <name>\n"); > > } > > ~ > > ~~~~~~~~~~~~~~~~~~~~ > Thanks and Best regards, > ~ Rajnikant > Software Engg. > Persistent Sys. Ltd. > Ph. +91 98222 04088 > > > > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Thursday, June 19, 2008 4:55 PM > To: [EMAIL PROTECTED] > Subject: Argument for perl script > > Hi All, > > I am using @ARGV variable to record the argument passed to my Perl script. > Now the requirement is that if I don't pass any argument to Perl script then > it should show me following such output. > > Perl ack > > Usage: ack > > -name > > -pkg > > -relno > > -name, -pkg, -relno are the user friendly option which should be mapped to > the arguments passed to the Perl script. > > So -name should take first argument -pkg should take second argument and so > on. > > Please help how should I do that. > > Regards > > Irfan. > > DISCLAIMER > ========== > This e-mail may contain privileged and confidential information which is the > property of Persistent Systems Ltd. It is intended only for the use of the > individual or entity to which it is addressed. If you are not the intended > recipient, you are not authorized to read, retain, copy, print, distribute or > use this message. If you have received this communication in error, please > notify the sender and delete all copies of this message. Persistent Systems > Ltd. does not accept any liability for virus infected mails.- Hide quoted > text - > > - Show quoted text -
use getopt module. see http://search.cpan.org/~rgarcia/perl-5.10.0/lib/Getopt/Std.pm -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/