How do I pass parameters into perl through command line?

Brad C

New member
I'm very new to Perl and reading and coding what I can. One thing I haven't been able to find out is how to pass a parameter from the command line into a variable in my script. For example if my file is called hello.pl I want to be able to run it as >perl hello.pl -world where "world" is stored as a variable for later use. I appreciate all your help!
 
my perl isn;t great but if i rememebr right comand line arguments are stored in the array

@ARGV

hope this helps.

Edit yep here's a simple example
#!/usr/bin/perl -w
print "argument 1 $ARGV[0] \n";
print "argument 2 $ARGV[1] \n";

or you can use this to loop through all of them
foreach $s (@ARGV) {

}

^_^
 
I give previous answer thumbs-up for the general case, even though he forgot "use strict; use warnings;" 8-P

If you want to parse options with minus signs, the de facto standard is to use the Getopt::Long module
 
Back
Top