CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Using @ARGV

 



yellowman
Novice

Apr 3, 2007, 7:43 AM

Post #1 of 4 (477 views)
Using @ARGV Can't Post

I am trying to learn how to use command line arguments using @ARGV

I am just trying to put together something simple to see how everything works. For instance I want to type something like test.pl 1, test.pl 2, test.pl 3 etc. and have something different print out depending on which command line argument is used.

I know I would put the 3 arguments in the @ARGV array, but then how would I write the if statements
to print something different out for each option?


KevinR
Veteran


Apr 3, 2007, 9:56 AM

Post #2 of 4 (476 views)
Re: [yellowman] Using @ARGV [In reply to] Can't Post

perl test.pl 1 2 3


test.pl:

print "$ARVG[0]\n";
print "$ARGV[1]\n";
print "$ARGV[2]\n";
-------------------------------------------------


PGScooter
stranger

Apr 3, 2007, 11:44 AM

Post #3 of 4 (472 views)
Re: [yellowman] Using @ARGV [In reply to] Can't Post


Quote
how would I write the if statements
to print something different out for each option?


if ($ARVG[0] == 1) {
print "The first value you inputted was 1! You must like the color red..."; ##sorry for the lame example, but you get the point :)
}
The more you teach me, the more I learn. The more I learn, the more I teach.


yellowman
Novice

Apr 3, 2007, 2:00 PM

Post #4 of 4 (468 views)
Re: [PGScooter] Using @ARGV [In reply to] Can't Post

Ha....I finally figured it out.

I was thinking that you had to assign the list of possible values to @ARGV.....

Here anything put on the command line is automatically placed in @ARGV.

Once I figured this out all was a snap. Thanks;-)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives