IT Community - Software Programming, Web Development and Technical Support

How do I read command-line arguments with Perl?

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 all, How do I read command-line arguments with Perl?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Perl

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 11-16-2007, 10:00 PM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Question How do I read command-line arguments with Perl?

Hi all,

How do I read command-line arguments with Perl?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-18-2007, 09:05 PM
ragavraj ragavraj is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 92
ragavraj is on a distinguished road
Default Re: How do I read command-line arguments with Perl?

In Perl command line argumnet are stored in @ARGV array

$ARGV[0] contains the first argument, $ARGV[1] contains the second argument, etc

Here is simple program for reading a n number of command line Inputs

PHP Code:
#!/usr/bin/perl
#---------------------#
#  PROGRAM:  commandlineinput.pl  #
#---------------------#

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

Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-26-2007, 05:43 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Cool Re: How do I read command-line arguments with Perl?

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.
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-26-2007, 05:43 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: How do I read command-line arguments with Perl?

Hi buddy....


Here's a simple program:

Code:
#!/usr/bin/perl 
$numArgs = $#ARGV + 1; 
print "thanks, you gave me $numArgs command-line arguments.\n"; 
foreach $argnum (0 .. $#ARGV) { 
print "$ARGV[$argnum]\n"; 
}
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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 08:25 PM
Using PHP from Command Line Sabari PHP Programming 4 12-18-2007 05:42 AM
How do I run a php script from the command line itbarota PHP Programming 1 09-11-2007 02:06 AM
How do I access command-line arguments? prasath C and C++ Programming 1 08-17-2007 10:46 PM
How do I read command-line arguments with Perl? sivaramakrishnan Perl 1 07-23-2007 03:50 AM


All times are GMT -7. The time now is 02:11 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0