I’m working on a Perl script. How can I pass command line parameters to it?
Example:
script.pl 'string1' 'string2'
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It depends on what you want to do. If you want to use the two arguments as input files, you can just pass them in and then use
<>to read their contents.If they have a different meaning, you can use
GetOpt::StdandGetOpt::Longto process them easily.GetOpt::Stdsupports only single-character switches andGetOpt::Longis much more flexible. FromGetOpt::Long:Alternatively,
@ARGVis a special variable that contains all the command line arguments.$ARGV[0]is the first (ie."string1"in your case) and$ARGV[1]is the second argument. You don’t need a special module to access@ARGV.