Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

cat /come/and/play/with/$i | perl -ne 'print if length((split /,/)[10] +) > 6'
BTW, I cannot restrain myself from commenting anytime I see cat being used like this because, long ago on usenet, Tom Christiansen wrote: "If you find yourself calling cat with just one argument, you're probably doing something silly".

Following Tom's advice, I suggest you lose the cat (and the unnecessary pipe) by replacing:

cat /come/and/play/with/$i | perl -ne 'print if length((split /,/)[10] +) > 6'
with simply:
perl -ne 'print if length((split /,/)[10]) > 6' /come/and/play/with/$i

Update: Added content from Useless Use of Cat Award (thanks choroba):

The venerable Randal L. Schwartz hands out Useless Use of Cat Awards from time to time; you can see some recent examples in Deja News. (The subject line really says "This Week's Useless Use of Cat Award" although the postings are a lot less frequent than that nowadays). The actual award text is basically the same each time, and the ensuing discussion is usually just as uninteresting, but there are some refreshing threads there among all the flogging of this dead horse. The oldest article Deja News finds is from 1995, but it's actually a followup to an earlier article. By Internet standards, this is thus an Ancient Tradition.

Nearly all cases where you have:

cat file | some_command and its args ...
you can rewrite it as:
<file some_command and its args ...
and in some cases you can move the filename to the arglist as in:
some_command and its args ... file

Also mentioned at this site are:

  • Useless Use of kill -9
  • Useless Use of echo
  • Useless Use of ls *b
  • Useless Use of wc -l
  • Useless Use of grep | awk and grep | sed
  • Useless Use of Backticks
  • Useless Use of Test
  • Assorted Other Gripes: Regular expressions used for searching (not substituting) that begin or end with '.*'. Actually 'anything*' or 'anything?'. If you are willing to accept "zero repetitions" of the anything, why specify it? Awk scripts that are basically cut unless reordering of fields is needed. Case conversions in comp.unix.shell (ex. how do I change my file names from UC to LC?) using tr/sed/awk/??? when some shells have builtin case conversions. Complex schemes to basically eliminate certain chars. For example DOS lines to UNIX lines. Sure read dos2unix(1), but using sed/awk/... when "tr -d '^M'" is all that is needed. Global changes to a file using sed to create a tmp file and renaming the tmp file, when an "ed(1)" here document would do fine.

Update: See also:


In reply to Re: perl one liner for csv file one field (useless use of cat and other awards References) by eyepopslikeamosquito
in thread perl one liner for csv file one field by MrTEE

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-03-28 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found