How Do I Run a Perl Script in Linux with Parameters?

How Do I Run a Perl Script in Linux with Parameters?
Contents

How do I pass a parameter to a Perl script?

If you want to use the two arguments as input files, you can just pass them in and then use <> to read their contents. Alternatively, @ARGV is 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.

How do I run a Perl script from Unix command line?

3 Answers

  1. Find the interpreter/executors path. In this case its /usr/bin/perl or /usr/bin/env perl.
  2. Add it to the first line of the file as #!/usr/bin/perl .
  3. Give execute permission to the file chmod +x example.pl.
Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.