DelphiFAQ Home Search:

Reading command line arguments from perl


comments8 comments. Current rating: 4 stars (5 votes). Leave comments and/ or rate it.


I am writing some command line tools to manipulate a large number of text files. How can I pass commandline arguments?


The command line can be read with @ARGV


$numArgs = $#ARGV + 1;
print "$numArgs command-line arguments.\n";

foreach $argnum (0 .. $#ARGV) {
   print "@ARGV[$argnum]\n";

Content-type: text/html


2006-09-18, 19:51:53
anonymous from United States  
Doesn't address what happens if there are no args provided.
2006-11-09, 12:29:25
anonymous from United States  
Doesn't address what to do with the arguments once you read them
2007-10-27, 22:03:01
ntg from United States  
if no args then it is -1+1=0....
2008-02-11, 02:57:05   (updated: 2008-02-11, 02:57:51)
anonymous from Germany  
Wasn't it explained in beginner's HOWTO on
2008-03-08, 20:44:07
It's probably going to work anyway, but shouldn't it be $ARGV[ $argnum]?
2008-05-21, 02:44:05
anonymous from Lithuania  
please RTFM
2008-07-08, 16:40:29
anonymous from United States  
Don't pay attention to the haters. This is exactly what I needed. Short & right to the point. THANKS!
2009-02-18, 11:15:31
anonymous from United States  
Thanks for the example. As the person before said, Short and right to the point. Thanks!



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: