Hi everyone,
I am currently working at learning perl but come up with two problems i can't clear on my own.
I use perl version 5.8 on windows xp
The complete I am working on is supposed to find motifs in a sequence.
This is the complete code
[CODE=perl]#!/usr/bin/perl -w
use strict;
#Searching for motifs
#Ask the user for the filename containing the sequence.
print "Type the filename you want to look at: ";
my $proteinfilenam e = <STDIN>;
#remove the newline from the protein filename
chomp $proteinfilenam e;
#open the file or exit
unless ( open(PROTEINFIL E, $proteinfilenam e) ) {
print "Cannot open the file \"$proteinfilen ame\"\n\n";
exit;
}
#Read the protein sequence from the file and store it into the array variable called @protein
my @protein = <PROTEINFILE> ;
#close the file
close PROTEINFILE;
#Now put everything into a single string as it is easier to search in a single string than in an array of lines (problem of line break as well.
my $protein = join('', @protein);
#remove whitespaces
$protein =~ s/\s//g;
#In a loop, ask the user for a motif, search for it and report if it was found
#exit if no motif entered
do {
print "Enter a motif to search for: ";
my $motif = <STDIN>;
# Remove the newline at the end of $motif
chomp $motif;
#look for the motif
If ( $protein =~ /$motif/ ) {
print "I found it!\n\n";
} else {
print "nop. \n\n";
}
# exit on an empty user input,
} until ( $motif =~ /^\s*$/ );
#exit the program
exit;[/CODE]
I tried several time to run it but it did not work and it even got worse when I tried to use the strict tag. The code is the same as the one I read in the book(beginning perl for bioinformatics, James Tisdall, Oreilly p65), I checked three times and could not figure out where was the mistake
These are the error/warning I got:
unknown 'strict' tag(s) '1' at Findmotifs.pl line7
Syntax error line 50 near ") {"
Syntax error line 54 near "} else"
Global symbol "$motif requires explicit package name at Findmotifs.pl line 61
I first though it was because of the strict but it wasn't
What is explicit package name?
Is there anyone who can tell me where I'm wrong (particularly at line 50 and 54 as to my point of view it seems to be correct according to what I have read in my textbook)
I want to add one last thing: that I added the whole code because I know that sometimes the mistake is not exactly where perl say it is.
Thanks in advance for your help
I am currently working at learning perl but come up with two problems i can't clear on my own.
I use perl version 5.8 on windows xp
The complete I am working on is supposed to find motifs in a sequence.
This is the complete code
[CODE=perl]#!/usr/bin/perl -w
use strict;
#Searching for motifs
#Ask the user for the filename containing the sequence.
print "Type the filename you want to look at: ";
my $proteinfilenam e = <STDIN>;
#remove the newline from the protein filename
chomp $proteinfilenam e;
#open the file or exit
unless ( open(PROTEINFIL E, $proteinfilenam e) ) {
print "Cannot open the file \"$proteinfilen ame\"\n\n";
exit;
}
#Read the protein sequence from the file and store it into the array variable called @protein
my @protein = <PROTEINFILE> ;
#close the file
close PROTEINFILE;
#Now put everything into a single string as it is easier to search in a single string than in an array of lines (problem of line break as well.
my $protein = join('', @protein);
#remove whitespaces
$protein =~ s/\s//g;
#In a loop, ask the user for a motif, search for it and report if it was found
#exit if no motif entered
do {
print "Enter a motif to search for: ";
my $motif = <STDIN>;
# Remove the newline at the end of $motif
chomp $motif;
#look for the motif
If ( $protein =~ /$motif/ ) {
print "I found it!\n\n";
} else {
print "nop. \n\n";
}
# exit on an empty user input,
} until ( $motif =~ /^\s*$/ );
#exit the program
exit;[/CODE]
I tried several time to run it but it did not work and it even got worse when I tried to use the strict tag. The code is the same as the one I read in the book(beginning perl for bioinformatics, James Tisdall, Oreilly p65), I checked three times and could not figure out where was the mistake
These are the error/warning I got:
unknown 'strict' tag(s) '1' at Findmotifs.pl line7
Syntax error line 50 near ") {"
Syntax error line 54 near "} else"
Global symbol "$motif requires explicit package name at Findmotifs.pl line 61
I first though it was because of the strict but it wasn't
What is explicit package name?
Is there anyone who can tell me where I'm wrong (particularly at line 50 and 54 as to my point of view it seems to be correct according to what I have read in my textbook)
I want to add one last thing: that I added the whole code because I know that sometimes the mistake is not exactly where perl say it is.
Thanks in advance for your help
Comment