#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Useqq = 1; $| = 1; my @sorted_cols = ( 2, 0, 1, 3 ); my %conwithposition = ( TITLE => [ 0, 'eq', [ 'Mr.', 'Mrs.', 'Ms.' ] ], HANDLE => [ 2, 'eq', 'BeginR' ], ); # TITLE, FIRST_NAME, HANDLE, LAST_NAME my @lines = ( "Mr.\tNice\tBeginR\tPerson", "Senator\tNice\tBeginR\tPerson", "Mr.\tBruce\tUtil\tGray", ); my @array = @lines; my $arrayref =\@array; foreach my $key_pos(keys(%conwithposition)) { my @arraynew; #print "KEYLOOP::(@{$conwithposition{$key_pos}}[1],@{$conwithposition{$key_pos}}[2])\n";#,$line[@{$conwithposition{$key_pos}}[0]])\n"; my $i=0; #print "ARR:@arraynew\n"; file:for (@$arrayref) { my $match = 0; my @line = split /\t/; #print "Line:::@$arrayref\n"; my ($op, $arg1, $arg2) = (@{$conwithposition{$key_pos}}[1],@{$conwithposition{$key_pos}}[2],$line[@{$conwithposition{$key_pos}}[0]]); $match = is_match($op,$arg2, $arg1); if ($match){ push @arraynew, $_; } $i++; } $arrayref = \@arraynew; } my @final_result = map { [ (split "\t")[@sorted_cols] ] } @{ $arrayref }; print Dumper \@final_result; sub is_match{ my ($operator,$valuesrc,$inputval_ref)=@_; my $i; if (ref $inputval_ref eq ''){ return 1 if ($valuesrc eq $inputval_ref); } if (ref ($inputval_ref) eq 'ARRAY'){ my @valuetomatch=@$inputval_ref; for $i(0 .. $#valuetomatch){ return 1 if ($valuesrc eq $valuetomatch[$i]); } } return 0; }