Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

by Sol-Invictus (Scribe)
on Jan 28, 2004 at 19:31 UTC ( #324749=perltutorial: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    (from perl --help)
    
  2. or download this
        -e, -p, -n,-l, -0,-a, -F, -M 
    
  3. or download this
        perl -e '$date=localtime(time); print $date;' 
    
  4. or download this
        perl -e "$date=localtime(time); print $date;"
    
  5. or download this
        perl -e '$date=localtime(time); print $date,"\n";'
    
  6. or download this
        perl -l -e '$date=localtime(time); print $date;'
    
  7. or download this
        while(<>) { }
    
  8. or download this
        perl -l -n -e 'print $1 if /(\w+ear)/' some.txt 
    
  9. or download this
    perl -l -n -e 'BEGIN{$sum=0;} $sum=$sum+ $1 if /(\d+)/;print $1; END {
    +print "Total: ",$sum}'
    
  10. or download this
        while(<>) { print ; }
    
  11. or download this
        perl -l -p -e 's/Microsoft/Micro\$\$\$oft/g' some.txt
    
  12. or download this
    perl -l -n -e 'BEGIN{open (OUT,/path/to/file || die } print  if /^.*\w
    +{2,}.*$/gm; END {close (OUT); }'
    
  13. or download this
        split;
    
  14. or download this
        perl -l -a -n -e 'print $F[5]' some.txt
    
  15. or download this
        perl -l -a -F: -n -e 'print $F[0]' /etc/passwd 
    
  16. or download this
        perl -012 -e ...
    
  17. or download this
        -00 ( paragraph mode) -0777 (slurp mode) 
    
  18. or download this
        -M like use Module; 
         
        -m is like use Module(); 
    
  19. or download this
        use Wallace(gromit); 
    
        $saveTheDay=gromit(data);
    
  20. or download this
        $saveTheDay=Wallace::gromit(data); 
    
  21. or download this
        perl -l -MNet::Telnet -e'print $Net::Telnet::VERSION'
    
  22. or download this
        perl -MLWP::Simple -e '$content = get("http://www.perlmonks.org/")
    +;print $content' 
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-10-20 11:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (75 votes), past polls