Another attempt to get you started. Your specification is not detailed enough, so you might need to tweak it. For example, I assumed 'filter' means do not output the line if the condition is met, while 'append' means do output. Also, I did not use the 'num_or_string', because the relation seems to indicate the types.
#!/usr/bin/perl use warnings; use strict; die "Usage: $0 filter_file input_file\n" unless @ARGV == 2; my @filters; my %dispatch; for my $op (qw/== != <= >= < > eq ne le ge lt gt/) { $dispatch{$op} = eval qq{ sub { \$_[0] $op \$_[1] } }; } use constant { COLUMN => 0, REL => 1, VAL => 2, TYPE => 3, # Ignored at the moment ACTION => 4 }; open my $DATA, '<', pop or die $!; my @col_names_arr = split ' ', <$DATA>; my %col_names; $col_names{$col_names_arr[$_]} = $_ for 0 .. $#col_names_arr; open my $FILTER, '<', pop or die $!; <$FILTER>; # Skip header line while (<$FILTER>) { my ($column, $rel, $val, $type, $action, $order, $rest) = split; die "Ivalid format at line $.\n" if $rest; die "Duplicate order $order at line $.\n" if $filters[$order - 1]; die "Unknown column $column at line $.\n" unless exists $col_names +{$column}; $filters[$order - 1] = [$column, $rel, $val, $type, $action]; } close $FILTER; while (<$DATA>) { my @data = split; FILTER: for my $f (@filters) { my $sub = $dispatch{$f->[REL]}; die "Unknown operator $f->[REL]\n" unless ref $sub; my $result = $sub->($data[$col_names{$f->[COLUMN]}], $f->[VAL] +); if ($result) { last FILTER if 'filter' eq $f->[ACTION]; if ('append' eq $f->[ACTION]) { print; } else { die "Unknown action $f->[ACTION]\n"; } } } }
Nothing gets printed for your sample input (I did not know what to do if no filter nor append matched). I had to add the following line to it to get any output:
0.7 abc 0.9
Both a and c are big enough not to be filtered and b equals the string.

In reply to Re: Comparing a Hash key with a variable (if statement) by choroba
in thread Comparing a Hash key with a variable (if statement) by dkhalfe

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.