Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
For me, one of the essential features of command-line facility is the pipe. Notice what sorts of operations you need to use often on command lines (sorting, grepping, extracting one or more columns from a list of lines, doing string substitutions, etc); usually you'll find a unix utility that does just one of these things quite well, with a lot of flexibility in how you can do that one thing.

If you have a particular need that is not easy to do with an existing tool, write an simple tool in perl to make that operation easy on the command line, and put it in your PATH. A typical situation is: I want to locate all files whose names contain "x", and whose size is greater than 10240 bytes, and determine the total space consumed by these files. (This could certainly be done completely (and fairly easily) in perl, but using standard command line tools in combination with perl makes it even easier (a lot less typing) and offers a lot of flexibility, esp. if your command-line-interface is like bash, and makes it possible to recall, edit and re-execute earlier commands:

find . -name '*x*' -type f -printf '%s\n' | perl -ne 'chomp;$s+=$_ if( +$_>10240);END{print "$s\n"}'

I found myself needing to sum columns like this quite often, in many different situations, so I wrote a perl script to do just this (with options for flexibility), reducing the above example to:

find . -name '*x*' -type f -printf '%s\n' | sumcol -min 10240
In general, if I'm writing "perl -e '...'" or "perl -ne '...'" etc on a command line, I'm not using a system call within that perl script -- it's quicker (less typing) to use the command line for running unix tools, and to pipe their output to a perl script when necessary to accomplish other things.

In reply to Re: Resource for command line "one-liner" interpretation by graff
in thread Resource for command line "one-liner" interpretation by Hagbone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (9)
    As of 2014-09-16 17:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (36 votes), past polls