in reply to Counting frequency of the regex matches

You can store the regexs in an array or hash and use another array or hash to store the counts. E.g.:
my @res = ( qr/this/, qr/that/, ..., qr//); my @matches; for each row $row: for my $i (0..$#res) { if ($row =~ m/$res[$i]/) { $matches[$i]++; last; } }
This example assumes you want to stop once you have matched something. By making the last re match anything you can keep track of the number of unmatched rows without special casing it. That is, $matches[-1] is the number of rows that didn't match any of the other regular expressions.

Replies are listed 'Best First'.
Re^2: Counting frequency of the regex matches
by throop (Chaplain) on Jun 06, 2008 at 04:23 UTC
    Brother pc88mxer,

    Huh?

    I'm confused by this snippet of code:

    for each row $row:
    That usage of each looks nothing like the perldoc on each. And I don't understand what row is doing as a bareword. Or the colon after $row.

    Could you point me to a place in the docs that would tell me what you're doing here? My thrashing around in the online documentation hasn't gotten me anywhere.

    throop

      "for each row $row:" seems like a comment, where either the "#" prefix was missed, or got included in the code section due to laziness of the poster.
      Sorry, it's pseudo code. I didn't know how the OP was generated the rows of the database, so I just wrote it out in English. I guess I been influenced too much by Knuth's Literate Programming.