Fandom

How To Wiki

How to read command-line arguments in a PERL script

1,795pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

To read arguments from a PERL script you use the environment variable ARGV.

  • Arguments are stored in the array @ARGV
    • First Argument: $ARGV[0]
    • Second Argument: $ARGV[1]
    • Third Argument: $ARGV[2]
    • etc.
  • Example
    • ./script.pl arg1 num2 bob
      • $ARGV[0] == "arg1"
      • $ARGV[1] == "num2"
      • $ARGV[2] == "bob"
  • To get the total number of arguments
    • $numberOfArguments = $#ARGV + 1;
  • To read all arguments as one string
    • $arg_string=join(' ',@ARGV);


From HowTo Wiki, a Wikia wiki.

Also on Fandom

Random Wiki