I was going to have a much more detailed response, but ++1nickt and ++haukex beat me to the "how to do it inside perl".

In other news, your first qw{cut -d"," -f17 $file | sort | uniq > $tmpfile} does not do what you think. Specifically, the qw form splits the text contained within on the spaces, making a list of 'cut', '-d","', ... in void context; use warnings would have told you

Possible attempt to separate words with commas at 1204245.pl line 13. Useless use of a constant ("cut") in void context at 1204245.pl line 1 +3. Useless use of a constant ("-d\",\"") in void context at 1204245.pl li +ne 13. ...
and then it would have died with a message like
1204245-data.tmp: No such file or directory at 1204245.pl line 15.
I am assuming you actually ran qx{cut -d"," -f17 $file | sort | uniq > $tmpfile}, which would have done what you claimed, but would have been better implemented with system, because qx takes the output and puts it in a string, which you were using in void context; system just executes the command.

That said, follow 1nickt and haukex advice for how to do it in perl, without invoking external commands, much more efficiently..

(argh: ++hippo even beat me to pointing out this error, plus the missing semicolon which I forgot to mention; I'm only still posting because of my sunk cost. *sigh*)


In reply to Re: search/grep perl/*nix by pryrt
in thread search/grep perl/*nix by Gtforce

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.