By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 836 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Syntax error in a motif finder code

P: 4
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

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2.  
  3.  use strict; 
  4. #Searching for motifs
  5. #Ask the user for the filename containing the sequence.
  6.  
  7. print "Type the filename you want to look at: ";
  8.  
  9.  
  10. my $proteinfilename = <STDIN>;
  11.  
  12. #remove the newline from the protein filename
  13.  
  14. chomp $proteinfilename; 
  15.  
  16. #open the file or exit
  17.  
  18. unless ( open(PROTEINFILE, $proteinfilename) ) {
  19.  
  20.     print "Cannot open the file \"$proteinfilename\"\n\n";
  21.     exit; 
  22. }
  23.  
  24. #Read the protein sequence from the file and store it into the array variable called @protein
  25. my @protein = <PROTEINFILE>;
  26.  
  27. #close the file 
  28. close PROTEINFILE;
  29.  
  30. #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.
  31.  
  32. my $protein = join('', @protein);
  33.  
  34. #remove whitespaces
  35. $protein =~ s/\s//g;
  36.  
  37. #In a loop, ask the user for a motif, search for it and report if it was found 
  38. #exit if no motif entered
  39.  
  40. do {
  41.     print "Enter a motif to search for: ";
  42.  
  43.     my $motif = <STDIN>;
  44.     # Remove the newline at the end of $motif
  45.  
  46.     chomp $motif;
  47.  
  48.     #look for the motif
  49.  
  50.     If ( $protein =~ /$motif/ ) {
  51.  
  52.         print "I found it!\n\n";
  53.  
  54.     } else {
  55.  
  56.         print "nop. \n\n";
  57.  
  58.     }
  59.  
  60. # exit on an empty user input,
  61. } until ( $motif =~ /^\s*$/ );
  62.  
  63. #exit the program
  64. exit;
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
Mar 31 '08 #1
Share this Question
Share on Google+
2 Replies


KevinADC
Expert 2.5K+
P: 4,059
one problem (line 50):

Expand|Select|Wrap|Line Numbers
  1. If ( $protein =~ /$motif/ ) {
all of perls operators and builtin functions use all lowercase letters, you have an uppercase I in "If", should be:

Expand|Select|Wrap|Line Numbers
  1. if ( $protein =~ /$motif/ ) {
fix that and rerun the code and see what errors you get.
Mar 31 '08 #2

P: 4
Thanks very much.
For the other error at line 61 I tried and figured out with the help of a friend that my value "$motif" was not declared until the end so I did that instead

Expand|Select|Wrap|Line Numbers
  1. #In a loop, ask the user for a motif, search for it and report if it was found 
  2. #exit if no motif entered
  3.  
  4. my $motif;
  5.  
  6. do {
  7.     print "Enter a motif to search for: ";
  8.  
  9.     $motif = <STDIN>;
  10.     # Remove the newline at the end of $motif
  11.  
  12.     chomp $motif;
  13.  
  14.     #look for the motif
  15.  
  16.     if ( $protein =~ /$motif/ ) {
  17.  
  18.         print "I found it!\n\n";
  19.  
  20.     } else {
  21.  
  22.         print "nop. \n\n";
  23.  
  24.     }
  25.  
  26. # exit on an empty user input
  27. } until ( $motif =~ /^\s*$/ );
  28.  
  29. #exit the program
  30. exit;
I just tell that to complete the thread if someone else have the same probleme.
Apr 1 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.