2 Replies - 886 Views - Last Post: 23 April 2009 - 08:00 AM

#1 Notorion  Icon User is offline

  • D.I.C Regular

Reputation: 35
  • View blog
  • Posts: 378
  • Joined: 17-February 09

passing parameters in perl

Post icon  Posted 21 April 2009 - 07:48 PM

Take the code below as an example
Lets say I would want to pass this program 3 parameters, and then use each of them in my project
note this program is run on a linux system

Ok, so I run my program like this on the command line
./testcase.pl HTML help field

i would think, due to the code below that it would print
HTML
help
field

But it doesn't, it just prints
HTML
HTML
HTML

#!/usr/local/bin/perl
use strict;
print "$ARGV[$0]\n";
print "$ARGV[$1]\n";
print "$ARGV[$2]\n";



So my question is, am I passing parameters wrong or accessing them in Perl incorrectly?

Is This A Good Question/Topic? 0
  • +

Replies To: passing parameters in perl

#2 KevinADC  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: passing parameters in perl

Posted 21 April 2009 - 11:46 PM

should be:

#!/usr/local/bin/perl
use strict;
print "$ARGV[0]\n";
print "$ARGV[1]\n";
print "$ARGV[2]\n";



the array indexes are numbers, not scalar variables.

This post has been edited by KevinADC: 21 April 2009 - 11:47 PM

Was This Post Helpful? 1
  • +
  • -

#3 dsherohman  Icon User is offline

  • Perl Parson
  • member icon

Reputation: 226
  • View blog
  • Posts: 654
  • Joined: 29-March 09

Re: passing parameters in perl

Posted 23 April 2009 - 08:00 AM

For handling command-line parameters, you may want to take a look at the Getopt::Std and/or Getopt::Long modules rather than doing it all yourself.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1