in reply to Comparing a Hash key with a variable (if statement)

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