When running perl -n
or perl -p
, each command line argument is taken as a file to be opened and processed line by line. If you want to pass command line switches to that script, how can I do that?
相关问题
- $ENV{$variable} in perl
- Is it possible to pass command-line arguments to @
- Redirecting STDOUT and STDERR to a file, except fo
- Change first key of multi-dimensional Hash in perl
- How do I get a filehandle from the command line?
相关文章
- Linux - change the hostname in the CLI
- Running a perl script on windows without extension
- Comparing speed of non-matching regexp
- Can NOT List directory including space using Perl
- Extracting columns from text file using Perl one-l
- Lazy (ungreedy) matching multiple groups using reg
- How do I tell DBD::mysql where mysql.sock is?
- What is a good way to deploy a Perl application?
There are three primary ways of passing information to Perl without using STDIN or external storage.
Arguments
When using
-n
or-p
, extract the arguments in theBEGIN
block.Command-line options
In a full program, you'd use Getopt::Long, but
perl -s
will do fine here.Environment variables
Here is a short example program (name it
t.pl
), how you can do it:Call it like that:
or (will add a prefix to every line):