#!/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.



In reply to Re: Pattern Matching using Array by jwkrahn
in thread Pattern Matching using Array by ravimore

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.