Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by Sol-Invictus (Scribe)
on Jan 28, 2004 at 19:31 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://324749]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-03-28 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found