How To Wiki

How to read command-line arguments in a PERL script

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

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
    • ./ 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