Just abt started learning Perl... am stuck with a problem
This, then, is the right time to read the posting guidelines for this
group.
Iam writing a code in which I have to search using a pattern like
Please be precise.
That can mean a number of things.
and then I have to see how many times this
pattern occurs...
I thought I'd use split for the purpose
So I used it like split /$pattern/, $sequence
It gives me a split loop error...
Always copy and paste exact error messages. I have no idea what a 'split
loop error' is.
I then tried initializing $pattern='HAHHAJHYRWUYRI' etc
then ran the program , this runs clean...
Actually I am generating pattern by concatenating all the lines of
file...
I am sure you meant something other than what you said here.
Iam enclosing the entire code...
Please avoid that as much as possible. Post the *smallest* program that
still runs and exhibits the problem with which you are seeking help.
Again, the posting guidelines show you how to do that.
Incidentally, trying to run your code results in:
D:\Home> prasanna.pl
Missing right curly or square bracket at D:\Home\prasanna.pl line 75, at
end of line
syntax error at D:\Home\prasanna.pl line 75, at EOF
Execution of D:\Home\prasanna.pl aborted due to compilation errors.
Please post code that runs.
#! /usr/bin/perl
use warnings;
use strict;
missing.
You use this string as a filename later on.
What array are you initializing here? Looking down, I see that you are
magically creating a global @proteinseq array in init_array. That makes
program flow very hard to figure out, especially when you come back to
look at it in a few months.
check_sequence() ;
sub init_array
{
my ($count) =0;
You don't use count for anything. What's the point?
open (PROTEINSEQ,"$proteinseq") || die ("Can't open the proteinseq
:$! ");
You don't need to quote the name of the file in the open call; see
perldoc -q always
while ( defined ( $proteinseq[$count] = <PROTEINSEQ> ) )
{
chomp( $proteinseq[$count]);
$proteinseq[$count] =~ s/ //g;
$count++;
}
}
It seems like the purpose of this routine is to remove all spaces and
newline characters from the input file. I will assume that is indeed the
objective. If you are doing that, I do not see the point of returning
the contents of the file as an array of lines. See the code after my
comments for an alternative.
sub check_sequence
{
@aa_list = ('V');
$count =6;
$pat ='';
I cannot figure out what this sub is supposed to do. Based on your
description, I am going to assume that you want to count how many times
the literal string '[^V]VV[^V]' occurs in the input file.
#! /usr/bin/perl
use strict;
use warnings;
my $seq = '[^V]VV[^V]';
my $contents;
while(<DATA>) {
chomp;
s/ //g;
$contents .= $_;
}
my $count = 0;
++$count while $contents =~ /\Q$seq\E/g;
print "$seq occurs $count times\n";
__DATA__
[^V]VV[^V] [^V] V V
[^V] xcf [^V] V
V
[^V] t
a
d
f
ggertg
[^V] V V
[^V]
D:\Home> prasanna.pl
[^V]VV[^V] occurs 4 times