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 #### 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 #### #!/usr/bin/perl use warnings; use strict; use Data::Dumper; #link to input file from command line - 2 arguments or error displayed; Set to respective variables @ARGV == 2 or die "Invalid number or arguments. Please re-run program and supply as arguments: \n1) the filter file and \n2) the input file."; my ($filter_file, $input_file) = @ARGV; open (FILTER,"$filter_file"); my @filter; ; # read one line from the file [HEADERS] while () { # read other lines chomp; # remove "\n" from the end of the line push @filter,[(split /\t/,$_)]; # create an array of the line by splitting it by , make a reference of it and push the reference to the @filter array close $filter_file if eof; } @filter = sort { $a->[5] <=> $b->[5] } @filter; # sort the array #PRINTS REFERENCES TO ARRAY FROM LEAST TO GREATEST REGARDING 'ORDER' COLUMN print Dumper \@filter; #### For Debugging Purposes my $num_elements = (@filter-1); #Number of elements in array - will be used to control loop when comparisons take place later in code #### open (IN, "$input_file") or die "Cannot open file: $!"; #variables my $x=0; my @keys; my @holder; my @array_hash; my $blank = "-"; my $numerical_value = "num"; my $string_value = "string"; my $filter_data = "filter"; my $append = "append"; open (OUTFILE, ">>OUTPUT_$input_file") or die "Cannot create an output file: $!"; while(my $line = ) { chomp($line); $x++; if ($x==1) { print OUTFILE $line, "\n"; (@keys)=split(/\t/, $line); } else { my $y=0; (@holder) = split(/\t/, $line); my %hash; for my $column (@holder) { $hash{$keys[$y]}=$column; $y++; } #### if ((eval "$hash{$filter[0]->[0]} $filter[0]->[1] $filter[0]->[2]") && (eval "'$hash{$filter[1]->[0]}' $filter[1]->[1] '$filter[1]->[2]'") && (eval "$hash{$filter[2]->[0]} $filter[2]->[1] $filter[2]->[2]")) { print OUTFILE $line, "\n"; } #### for(my $c = 0; $c <= $num_elements; $c++) { if($hash{$filter[$c]->[4]} eq $filter_data) { if (exists($hash{$filter[$c]->[0]})) { if($hash{$filter[$c]->[3]} eq $numerical_value) { # #process filtering for numerical value if ((eval "$hash{$filter[$c]->[0]} $filter[$c]->[1] $filter[$c]->[2]")) { print OUTFILE $line, "\n"; } } } else { print "COLUMN NAME DOES NOT EXIST. CHECK FILTER FILE FOR ANY POSSIBLE ERRORS AND RE-RUN PROGRAM. PROGRAM WILL NOW TERMINATE.", "\n"; exit 0; } } }