in reply to Pattern Matching using Array

#!/usr/bin/perl-w

You need a space between the program name and any switches you need to pass to the program.    Better to just use the warnings pragma:

#!/usr/bin/perl use warnings;

open(my $outfile, ">", "Motif_Result.txt"); ... open(FIH, $patternseq);

You should always verify that the file opened correctly:

open my $outfile, '>', 'Motif_Result.txt' or die "Cannot open 'Motif_R +esult.txt' $!"; ... open FIH, '<', $patternseq or die "Cannot open '$patternseq' $!";

my $in; while ($in=<FIH>) { chomp($in); my @pats=split " ",$in; my $residue=shift@pats;

That could more simply be written as:

while ( <FIH> ) { my ( $residue, @pats ) = split;

foreach my $nnn (@pats) # @pats = (AAAAA, TTTTT, GGGGG); { $patsmap{$nnn}=@residue; }

You don't put any values into @residue so that is the same as saying:

foreach my $nnn (@pats) # @pats = (AAAAA, TTTTT, GGGGG); { $patsmap{$nnn} = 0; }

Perhaps you meant to use $residue instead of @residue?


print "Patterns\t"; print "@pats"; print "\n"; my $length = @pats; print "Total Patterns are: $length"; print "\n";

Instead of five separate prints you just need one:

print "Patterns\t@pats\nTotal Patterns are: ", scalar @pats, " +\n";

my @l = split('', $str); my $length=@l;

That is usually written as:

my $length = length $str;

exit; }

You exit the program at the bottom of the loop so you only ever read one line from your 'pat.txt' file.