There are a raft of techniques that clean your code up. The first is to throw the CSV file parsing over to a tool built for the job (Text::CSV). After that tossing the eval stuff aside and using a match function cleans up the rest of the code something wonderful. Consider:

#!/usr/bin/perl use warnings; use strict; use Text::CSV; use 5.010; my $ops = <<OPS; column relationship value num_or_string filter_or_append + order a <= 0.3 num filter 1 b eq abc string append 3 c <= 0.3 num filter 2 OPS my $csv = Text::CSV->new ({sep_char => "\t"}); open my $opsIn, '<', \$ops or die "Cannot open file: $!"; $csv->column_names($csv->getline($opsIn)); my @ops = @{$csv->getline_hr_all($opsIn)}; close $opsIn; my %filtColumns = map {$_->{column} => 1} @ops; my @inColumns = @{$csv->getline(*DATA)}; if (grep {! exists $filtColumns{$_}} @inColumns) { die <<DIE; COLUMN NAME DOES NOT EXIST. CHECK FILTER FILE FOR ANY POSSIBLE ERRORS +AND RE-RUN PROGRAM. PROGRAM WILL NOW TERMINATE. DIE exit 0; } $csv->column_names(@inColumns); $csv->combine(@inColumns); print $csv->string (), "\n"; while (my $line = $csv->getline_hr(*DATA)) { next if grep {! match($line, $_)} @ops; $csv->combine(@{$line}{@inColumns}); print $csv->string (), "\n"; } sub match { my ($line, $filter) = @_; my %fields = %$filter; my $value = $line->{$fields{column}}; given($fields{relationship}) { when ('<=') {return $value <= $fields{value}} when ('eq') {return $value eq $fields{value}} default { die "match can't handle $fields{relationship} operator\n"; } } } __DATA__ a b c 0.2 abc 0.3 0.1 abd 0.3 0.4 abe 0.2 0.1 abc 0.5 0.7 abt 0.7 0.1 abd 0.8

Prints:

a b c 0.2 abc 0.3

No doubt I've missed the significance of some of your code (I've not followed along on your whole journey to this point), but the sample code above should give you a good starting point for further development.

True laziness is hard work

In reply to Re: Comparing a Hash key with a variable (if statement) by GrandFather
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.