First off, a few things you need to do always in your code:

Then there are a few things that will help your PerlMonks nodes:

Ok, now that's out of the way. Here is what may constitute a solution to your problem:

use strict; use warnings; my $conditions_txt_file = <<FILESTR; 1 eq 1720 5 eq R FILESTR my $test_txt_file = <<FILESTR; 0,1720,123,123,13,123 0,1720,123,123,13,R 0,465,123,123,13,123 FILESTR my @conditions; open my $c_card, '<', \$conditions_txt_file or die "Can't open conditi +ons file: $!\n"; while (<$c_card>) { chomp; next if ! length; push @conditions, [split ' ']; } close $c_card; open my $testHandle, '<', \$test_txt_file or die "Can't open data nfil +e: $!\n"; while (<$testHandle>) { chomp; next if ! length; my @columns = split ','; next if grep {! match ($_, @columns)} @conditions; print join (',', @columns), "\n"; } close $testHandle; sub match { my ($cond, @columns) = @_; my ($column, $test, $value) = @$cond; if ($test eq 'eq') { return if $column < 0 || $column >= @columns; my $match = $columns[$column] eq $value; return $match; } else { die "Don't know how to perform '$test' test\n"; } }

Prints:

0,1720,123,123,13,R

The 'tricky' matching stuff is tucked away in a subroutine that is called within a grep that applies each test to the line being checked and returns a count of failed tests. If none failed they must all have succeeded and the line gets printed. If the number of conditions is huge there may be an advantage in using an explicit loop rather than using grep, but for most purposes grep is likely to be much easier to understand and plenty fast enough.


True laziness is hard work

In reply to Re: perl if condition by GrandFather
in thread perl if condition by castle

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.