473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Syntax error in a motif finder code

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
2 2567
KevinADC
4,059 Expert 2GB
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
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

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

Similar topics

1
by: maRIO5 | last post by:
I have Mandrake 9.0 and I downloaded Motif version of eclipse, but after I unziped, set the PATH and started: Eclipse -data /home/mario/Documents/eclipse/ I got a message that startup.jar is not...
1
by: Daniel Tscharnuter | last post by:
Hello! First of all, I am new to C++. The problem with the scale widget is that I get a segmentation fault when I want to create it with more than zero decimal numbers. beta_scale_ =...
4
by: Wanhua Yi | last post by:
Hi all, anybody out there with experience in using EMC's Time Finder Software and DB2 UDB EEE on AIX ? Especially in using BCV for Backup ? Any white papers ?
2
by: toufik | last post by:
Hi, I'm having the folowing error when I create a mondosearch finder instance Finder myFinder = new Finder("c:/Mondosearch/SearchHost/Data/MssOptions.xml",new CultureInfo("EN")); ...
0
by: C.W.Holeman II | last post by:
For info on the context of my question see the end of this posting. I have used resource files and xnlLanguage to control the language displayed in a Motif application. Simply dropping an...
94
by: Chad | last post by:
On to top of page 163 in the book "The C Programming Langauge" by K & R, they have the following: char *strdup(char *s) { char *p; p=(char *)malloc(strlen(s)+1); if( p != NULL) strcpy(p,s):...
8
by: cloh | last post by:
Thanks to all the people who reply so promptly to my questions! I have another one related to the form I am working on. When I try to call this function from another, I get the "Object variable or...
0
by: brahimbb17 | last post by:
There is no foolproof way to always win when gambling http://crop-finder-for-travian.blogspot.com . That is why it’s called gambling, you take risks and reap the benefits when lady lucks sides by...
1
by: willpfeiff | last post by:
Can I use VB to emualte a Motif application front end? Is there a Motif skin? I have done some preliminary research but no simple answers. Anybody tried this before? Should I just develop on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.