I also tired the below one....
my $r = `gunzip -c $file|cut -f3 -d'|'|sort|uniq -c`;
my $c1 = substr( $r, 16,-2);
my $c2 = substr( $, 9,-9);
This gives me the output as...
<code> $c1 = 4 $c1 = 6 <code>
I have a question to experts, was this correct method
In a word, no. It might (and I emphasize, might) work for your current input. What happens, though, when:
- You need to add, remove, or change one of the keywords you are interested in?
- Someone gives you a data file containing an entry like this: GHI|789|DHECK|1|
- Pretty much anything changes with the format of the output from that pipeline?
- Someone asks you, "hey, why doesn't this work on Windows?"
- You forget whether $c1 has the value for CHECK...or was it $c2?
- ...
Maybe you'll be ridiculously lucky and not ever encounter any of the above scenarios. But I guarantee, if you continue writing code that takes inherently variable width text input and parses it with fixed offsets, it will blow up horribly at some point.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.