Yes, almost every option on the command line translates to Perl code that you can use in your script. This is covered almost entirely in perlrun (see this for the -i switch). Corion showed how to use B::Deparse, but note that the code it shows is often a little longer than it needs to be. For example, perl -lane 'print $F[2]' can be written like the following. I've added warnings and strict, and used my @F instead of our @F and local $\ to limit their scope.
use warnings; use strict; local $\ = "\n"; # -l while (<>) { # -n chomp; # -l my @F = split; # -a print $F[2]; # -e }
Also note that Perl parses command-line options on the shebang line. So for example, to get the effect of -s (rudimentary command-line switches) without having to specify it on the command line:
$ cat s.pl #!/usr/bin/perl -s use warnings; use strict; our $x; print "<$x>\n"; $ ./s.pl -x=foo <foo>
In reply to Re: option control in script
by haukex
in thread option control in script
by dideod.yang
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |