#!/usr/bin/perl # This is a script which compares the query file and base with some # threshold given by the user use strict; use warnings; $| = 1; print "Enter the Threshold Value: \n"; my $j = <>; chomp $j; my $query_data = read_data( '10.asc.output' ); my $dir = '/home/users/dachs/perl_scripts/perlup'; #dir path where opendir my $dh, $dir or die "System can't open directory for reading\n"; while (my $filename = readdir $dh) { next unless $filename =~ /\.asc.output$/i; my $base_data = read_data( $filename ); open my $out, ">$filename.cmp" or die "cannot open file for writing: $!"; # Creates an output file my @r = map abs( $query_data->[ $_ ] - $base_data->[ $_ ] ), 0, 1; my $i = 2; while ( $i < @$query_data ) { $r[ $i % 3 ] = abs( $query_data->[ $i ] - $base_data->[ $i ] ); if ( $r[ 0 ] <= $j && $r[ 1 ] <= $j && $r[ 2 ] <= $j ) { my $matched = join "\t", @{ $query_data }[ $i-2..$i ]; print $out "Matched: $matched\n"; } $i++; } close $out; } closedir $dh; sub read_data { my $filename = shift; open my $in, $filename or die; my @data; while ( <$in> ) { push @data, $1 if /(\S+)\s+\S+/; # difficult to advise on regex # without knowing the details of # the data } close $in; return \@data; }