I can do this easily in bash, but it's slow on big files due to the hard drive i/o limitations. So I need to load the files into memory and do the same. Here is the method via bash: grep $SEARCH_TERM $FILE_1 | grep -c Z Basically it's grepping each line of a file for 2 conditions and returns the total count. How do I do this in perl? I tried loading the entire file into an array:
open my $C_LOC, '<', $C_LOCATIONS_FILE; chomp(my @C_LOC_ARRAY = <$C_LOC>); close $C_LOC;
But but scanning the array turns into a mess pretty quickly. Again, I'm using arrays because these are big files (gigabytes) and I need to do thousands of searches without having to load the file from hard drive each time. Thank you so much for the help! EDIT:
================
This takes 46 seconds:

my @foo = grep (/100008020/, @C_LOC_ARRAY); my @foo2 = grep (/Z/,@foo);

This takes 0.823 seconds
 grep 100008020 OT.file | grep -c Z

How do I speed up my perl?

EDIT #2
================
I have a flat (text file) that looks like this:

Tommy Z
Tommy Z
Chris Z
Chris B
Chris Z
Jake Z
Jake Y

I'm simply counting how many Z's each person has and ignoring all other letters.

Output would look like this for 8 million people

Tommy 2
Chris 2
Jake 1

In reply to Nested greps w/ Perl by wackattack

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.