Wikia

How To Wiki

How to read command-line arguments in a PERL script

1,794pages on
this wiki
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
    • ./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.

Around Wikia's network

Random Wiki