Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Uncommon* but Useful Perl Command Line Options

by Abigail-II (Bishop)
on Jan 29, 2004 at 00:20 UTC ( #324839=note: print w/ replies, xml ) Need Help??


in reply to Uncommon* but Useful Perl Command Line Options for One-liners

you could pass a 200 line script like this - though you might find it a pain to write all on one line.
So, write it on multiple lines. -e may be repeated:
$ perl -wl -e 'print "This is line 1";' \ -e 'print "This is line 2";' \ -e 'print "This is line 3";' \ -e 'print "This is line 4";' \ -e 'print "This is line 5";'
works like a charm.
-p (looping plus)

in longhand it looks like this:

while(<>) { print ; }
Actually, it's a bit more subtle than that, as can be shown by using the deparser:
$ perl -MO=Deparse -pe '1' LINE: while (defined($_ = <ARGV>)) { '???'; } continue { print $_; } -e syntax OK
The print is done in a continue block, so it will print even if you use next in the supplied code. Note also the label.
-a (split)

in longhand:

split;
Well, that should be: @F = split;, but it should be noteworthy that -a only works in combination with -n or -t.
perl -01512 -e
This is what I get when I run it:
$ perl -01512 -e 1 Unrecognized switch: -2 (-h will show valid options). $
You can only use -0 to set $/ to a one character string - not to set it to \r\n.

Abigail


Comment on Re: Uncommon* but Useful Perl Command Line Options
Select or Download Code
Re: Re: Uncommon* but Useful Perl Command Line Options
by Sol-Invictus (Scribe) on Jan 29, 2004 at 00:27 UTC
    erratum and tips noted, but - the tut does say that -a outputs to @F - entering a 200 line script on the command line with continuation lines - I'd prefer to write that as a .pl file :)
Re: Re: Uncommon* but Useful Perl Command Line Options
by ysth (Canon) on Jan 29, 2004 at 00:37 UTC
    -a only works in combination with -n or -t
    I assume this is a typo and Abigail meant -n or -p.

    Actually, even without -n or -p, the -a switch does have the very minor effect of creating @F, so that referring to it won't get you a Name "main::F" used only once: possible typo warning. (And *F{ARRAY} will give a reference to @F even if no @F is mentioned anywhere, instead of the usual undef.)   These could be construed as a bug.

      These could be construed as a bug. (sic)
      ..or as devious tools to use for strict-safe obfuscation. Mu-ha-ha-ha-ha. ;)

      thor

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://324839]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2014-10-02 06:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (49 votes), past polls