Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by sfink (Deacon)
on Jan 29, 2004 at 17:50 UTC ( #324988=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    perl -l -n -e 'BEGIN{$sum=0;} $sum=$sum+ $1 if /(\d+)/;print $1; END {
    +print "Total: ",$sum}'
    
  2. or download this
    echo -e "a\nb\nc" | perl -lne 'next if /b/; print'
    a
    c
    echo -e "a\nb\nc" | perl -lne 'last if /b/; print'
    a
    
  3. or download this
    perl -lne 'print $s += $1 if /(\d+)/'