@Patterns=("xxx", "SSS", "s:S"); sub getCsvHash { %master=(); # unset the HASH. foreach my $wlp (@Patterns) { my $key=$wlp; $key =~ s/[\s+|:]/_/g; open FILE, "csv_file.csv" or die $!; while() { my $line=$_; { my @csv = split(",", $line); if ($csv[1] =~ /"$wlp/) { push (@{$master{$key}}, $line); # push as value of a hash } } } #while() ends here close FILE; } #foreach $wlp ends here } #Function getWhiteListCsvArrays ends here. sub Processfiles { open DFH, "$log_file"; while() { my $line=$_; if ($line =~/(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)\t(.*?)/) { my $rc=$3; my $ct=$10; my $cl=$6; my $retval=applyList($line,$rc,$cl,$ct) } } } sub applyList { foreach my $row (@{$master{$key}}) { my $param_op1_flag="nc"; #Set the flag to indicate that the optional parameter 1 is nc(not-checked). my $param_op2_flag="nc"; #Set the flag to indicate that the optional parameter 2 is nc(not-checked). my @row_csv = split(",", $row); $row_csv[3] =~s/"(.*?)"/$1/g; #Get the mandatory part 1. This is the domain-name. $row_csv[4] =~s/"(.*?)"/$1/g; #Get the mandatory part 2. This is part after domain-name. my $param_man = $row_csv[3] . $row_csv[4]; #combine the mandatory parts. my $param_op1=$row_csv[5]; #Get the optional parameter 1. my $param_op2=$row_csv[6]; #Get the optional parameter 2. $param_op1=~ s/\n//g; #Remove the new-lines if any. $param_op2=~ s/\n//g; #Remove the new-lines if any. if(length($param_op1)) #check if optional parameter 1 has something to check or not. { $param_op1 =~s/"(.*?)"/$1/g; #Remove the double inverted commas. $param_op1 =~s/\?/\\\?/g; #Escape the special characters like: ?. if($url =~/$param_op1/) #check if optional parameter 1 is present in URL or not. { $param_op1_flag="cf"; #Set the optional parameter 1 flag to cf (checked-found). } else { $param_op1_flag="cnf"; #Set the optional parameter 1 flag to cnf (checked-not-found). } } if(length($param_op2) > 1 ) { $param_op2 =~s/"(.*?)"/$1/g; #Remove the double inverted commans. $param_op2 =~s/\?/\\\?/g; #Escape the special characters like: ?. if($url =~ /$param_op2/) #check if optional parameter 2 is present in URL or not. { $param_op2_flag="cf"; #Set the optional parameter 2 flag to cf (checked-found). } else { $param_op2_flag="cnf"; #Set the optional parameter 2 flag to cnf (checked-not-found). } } if($url=~/$param_man/ && ($param_op1_flag eq "cf" || $param_op1_flag eq "nc") && ($param_op2_flag eq "cf" || $param_op2_flag eq "nc")) { if (($cl < 5000 || $rc == 206) && $key =~/^AS_D/) { open OPF, ">>out/$key_cont"; print OPF $line; close OPF; applyBlackList($line,$key_cont,$ct); $retval_def=1; return $retval_def; } open OPF, ">>out/$key"; print OPF $line; close OPF; if($key !~/^AD/) { applyBlackList($line,$key,$ct); } $retval_def=1; return $retval_def } } } return $retval_def; } } }