The best way depends on the patterns. Anyway I think you should first preprocess your patterns so that you don't have to compare the same values over and over again. Let's say you had just three columns and these four patterns:

p1: c1 = 5, c3 = 8
p2: c1 = 5, c3 = 4
p3: c2 = 4, c3 = 1
p4: c2 = 3, c3 = 5
so you would build a structure like this:
%patterns = ( 5 => { undef => { 8 => ['p1'], 4 => ['p2'] } }, undef => { 4 => { 1 => ['p3'] }, 3 => { 5 => ['p4'] } } );
and whenever you'd need to find all patterns that a match the current row you'd traverse this structure and find all leafs to which you can get through the keys matching the value of the columns or undefs. Eg. if the current row is 5,3,8 you'd first select both $patterns{5} and $patterns{undef()}, then after next step $patterns{5}{undef()} and $patterns{undef()}{3} and at last would end up with just @{$patterns{5}{undef()}{8}}=(p1). Not sure I make much sense, so let's try an example:
my @row = the data, without the record_id!; my @matching = (\%patterns); while (@row and @matching) { my $value = shift(@row); my @next_matching; foreach my $branch (@matching) { if (exists $branch->{$value}) { # there is a matching pattern if (ref($branch->{$value}) eq 'HASH') { # the pattern requ +ires some more values to match push @next_matching, $branch->{$value}; } else { # the pattern matched completely push @found_patterns, @{$branch->{$value}}; } } if (exists $branch->{undef()}) { # there is a patter that does +n't care about this value if (ref($branch->{undef()}) eq 'HASH') { # the pattern req +uires some more values to match push @next_matching, $branch->{undef()}; } else { # the pattern matched completely push @found_patterns, @{$branch->{undef()}}; } } } @matching = @next_matching; } # and now all the matching patterns are in @found_patterns # the code is untested and only intended as an example

Actually you may need to use a different value to mean "don't care" in the structure if some patterns require that some columns equal null and null != "".

I would use Text::CSV_XS to do the actual reading and parsing of the text file.

Jenda
We'd like to help you learn to help yourself
Look around you, all you see are sympathetic eyes
Stroll around the grounds until you feel at home
   -- P. Simon in Mrs. Robinson


In reply to Re: Best way to find patterns in csv file? by Jenda
in thread Best way to find patterns in csv file? by punch_card_don

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.