Syntax error in a motif finder code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • HalfCoded
    New Member
    • Mar 2008
    • 4

    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

    [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
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    one problem (line 50):

    Code:
    If ( $protein =~ /$motif/ ) {
    all of perls operators and builtin functions use all lowercase letters, you have an uppercase I in "If", should be:

    Code:
    if ( $protein =~ /$motif/ ) {
    fix that and rerun the code and see what errors you get.

    Comment

    • HalfCoded
      New Member
      • Mar 2008
      • 4

      #3
      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

      [CODE=perl]#In a loop, ask the user for a motif, search for it and report if it was found
      #exit if no motif entered

      my $motif;

      do {
      print "Enter a motif to search for: ";

      $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 just tell that to complete the thread if someone else have the same probleme.

      Comment

      Working...