syntax error at. / friends.cgi ligne 31, près de "elsif"

  • Belinda
  • Born
  • Born
  • No Avatar
  • Inscription: Mar 02, 2004
  • Messages: 2
  • Status: Offline

Message Mars 2nd, 2004, 4:21 pm

Salut tous;
Ive rying pour trouver l'erreur dans mon codage mais je ne peux pas.

Quelqu'un peut-il voir ce qui im mal faire
Je appricate it.Here est mon codage
Tels sont les messages d'erreur qui Im réception

Erreur de syntaxe à la ligne. / friends.cgi 31, près de "elsif"
Erreur de syntaxe à la ligne. / friends.cgi 57, near ")"
***********
Code: [ Select ]
#!/usr/bin/perl -w

use CGI qw/:standard/;

#print all headers
print header();
print start_html ( "Who is your friend?" );
#Display database content in case of starighforward GET
#if (request_method() eq "GET")
{
    open FRIENDS ,"friends.dat";
    print "<h3>These are my friends:</h3>\n";
    print"<table> \n " ;
    while ( <FRIENDS> )
    {
    chomp ;
    @fields = split / \ | / ;
    
    #Each record will be a self-contained form used for updating records
    print qq~\t<tr>\n~;
    print qq~\t\t<td><form method="POST" action="/cgi-bin/firends.cgi"> \n~ ;
    print qq~\t\t\t$fields[1] - $fields[2]\n~ ;    
    print qq~\t\t<td><input type="submit" value="Change" name="submit">~;
    print qq~<input type="hidden" name="key" value="$fields[0]">\n~;
    print qq~</form> \n~;
}
print "</table> \n";
}

#This request is an update is in progress
elsif (request_method() eq "POST")
{
    if (param('submit') eq "Change" )
    {
        open FRIENDS,"friends.dat";
        
        print "<h3>Changing record </h3>";
        print qq~<form method="POST" action="/cgi-bin/friends.cgi"> \ n~;
        while (<FRIENDS>)
        {
            @fields = split / \ | / ;
        
            #This tries to locate the desired record
            if ($fields[0] eq param('key'))
            {
            #print the chosen record in editable text boxes
            #everything except the product ID number is editable
            print qq~Name:<input type="text" name="name" value=$fields[1]" ><br>\n~;
            print qq~Phone: <input type="text" name="phone" value=$fields[2]" ><br>\n~;    
            print qq~<input type="hidden" name="key" value="$fields[0]" ><br>\n~;
            print qq~<input type="submit" name="submit" value="Save" > \n~;
            
            last;
            }
        }
        print "</form> \n" ;
    }
    else
    {
        #Open the database for exclusive read and write access
        open FRIENDS , " + <friends.dat" ;
        flock (FRIENDS,2);

        #Create a temporary file for updates and lock it
        open TEMP,"temp.dat";
        Flock (TEMP,2);

        while (<FRIENDS>)
        {
            @fields = split / \ | / ;
            
            #Create a temproray image of the databse with the updated record
            if ($fields[0] eq param('key'))
            {
                #Replace the edited record with the updated content
                print TEMP param( 'key' ) .  " | ". param( 'name' ) . " | " . param (
'phone' ) . "\n";
            }
            else
            {
                #All "other" records are processed unchanged
                print TEMP $_;
            }
        }
        #Overwrite the previous database with the updated version
        unlink "friends.dat";
        rename "temp.dat", "friends.dat";

        print"<h3>information saved!</h3>";

        close TEMP;
    }
}

#finish-up and cleanup
print end_html( );
close FRIENDS;
  1. #!/usr/bin/perl -w
  2. use CGI qw/:standard/;
  3. #print all headers
  4. print header();
  5. print start_html ( "Who is your friend?" );
  6. #Display database content in case of starighforward GET
  7. #if (request_method() eq "GET")
  8. {
  9.     open FRIENDS ,"friends.dat";
  10.     print "<h3>These are my friends:</h3>\n";
  11.     print"<table> \n " ;
  12.     while ( <FRIENDS> )
  13.     {
  14.     chomp ;
  15.     @fields = split / \ | / ;
  16.     
  17.     #Each record will be a self-contained form used for updating records
  18.     print qq~\t<tr>\n~;
  19.     print qq~\t\t<td><form method="POST" action="/cgi-bin/firends.cgi"> \n~ ;
  20.     print qq~\t\t\t$fields[1] - $fields[2]\n~ ;    
  21.     print qq~\t\t<td><input type="submit" value="Change" name="submit">~;
  22.     print qq~<input type="hidden" name="key" value="$fields[0]">\n~;
  23.     print qq~</form> \n~;
  24. }
  25. print "</table> \n";
  26. }
  27. #This request is an update is in progress
  28. elsif (request_method() eq "POST")
  29. {
  30.     if (param('submit') eq "Change" )
  31.     {
  32.         open FRIENDS,"friends.dat";
  33.         
  34.         print "<h3>Changing record </h3>";
  35.         print qq~<form method="POST" action="/cgi-bin/friends.cgi"> \ n~;
  36.         while (<FRIENDS>)
  37.         {
  38.             @fields = split / \ | / ;
  39.         
  40.             #This tries to locate the desired record
  41.             if ($fields[0] eq param('key'))
  42.             {
  43.             #print the chosen record in editable text boxes
  44.             #everything except the product ID number is editable
  45.             print qq~Name:<input type="text" name="name" value=$fields[1]" ><br>\n~;
  46.             print qq~Phone: <input type="text" name="phone" value=$fields[2]" ><br>\n~;    
  47.             print qq~<input type="hidden" name="key" value="$fields[0]" ><br>\n~;
  48.             print qq~<input type="submit" name="submit" value="Save" > \n~;
  49.             
  50.             last;
  51.             }
  52.         }
  53.         print "</form> \n" ;
  54.     }
  55.     else
  56.     {
  57.         #Open the database for exclusive read and write access
  58.         open FRIENDS , " + <friends.dat" ;
  59.         flock (FRIENDS,2);
  60.         #Create a temporary file for updates and lock it
  61.         open TEMP,"temp.dat";
  62.         Flock (TEMP,2);
  63.         while (<FRIENDS>)
  64.         {
  65.             @fields = split / \ | / ;
  66.             
  67.             #Create a temproray image of the databse with the updated record
  68.             if ($fields[0] eq param('key'))
  69.             {
  70.                 #Replace the edited record with the updated content
  71.                 print TEMP param( 'key' ) .  " | ". param( 'name' ) . " | " . param (
  72. 'phone' ) . "\n";
  73.             }
  74.             else
  75.             {
  76.                 #All "other" records are processed unchanged
  77.                 print TEMP $_;
  78.             }
  79.         }
  80.         #Overwrite the previous database with the updated version
  81.         unlink "friends.dat";
  82.         rename "temp.dat", "friends.dat";
  83.         print"<h3>information saved!</h3>";
  84.         close TEMP;
  85.     }
  86. }
  87. #finish-up and cleanup
  88. print end_html( );
  89. close FRIENDS;
  • Anonymous
  • Bot
  • No Avatar
  • Inscription: 25 Feb 2008
  • Messages: ?
  • Loc: Ozzuland
  • Status: Online

Message Mars 2nd, 2004, 4:21 pm

  • RichB
  • Guru
  • Guru
  • Avatar de l’utilisateur
  • Inscription: Mai 17, 2003
  • Messages: 1121
  • Loc: Boston
  • Status: Offline

Message Mars 2nd, 2004, 4:34 pm

Je ne sais pas vraiment perl, donc je n'ai pas regardé de près au code, mais il semble que vous avez un symbole de commentaire ( #) Avant que le cas sur la ligne 10.
Free Programming Resources
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • Avatar de l’utilisateur
  • Inscription: Mai 28, 2003
  • Messages: 23404
  • Loc: Woodbridge VA
  • Status: Offline

Message Mars 2nd, 2004, 5:01 pm

Im pensant que la première ligne de référence est le principal coupable:

Code: [ Select ]
elsif (request_method() eq "POST")


qui ne devrait pas être:
Code: [ Select ]
else if (request_method() eq "POST")


Im not a wiz à Perl non plus, mais que, tout ne semble pas correcte.


En tant que Belinda Sidenote - s'il vous plaît utiliser les portions de code entre parenthèses lors de la publication du code. 9 fois sur dix, il sera à vis de votre poste si vous n'avez pas.
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • RichB
  • Guru
  • Guru
  • Avatar de l’utilisateur
  • Inscription: Mai 17, 2003
  • Messages: 1121
  • Loc: Boston
  • Status: Offline

Message Mars 2nd, 2004, 5:07 pm

Im pretty sure elsif est valable en perl, mais si le premier cas est caché par une observation puis l'erreur peut être signalé lorsque la elsif a été vu depuis qu'il ne serait pas le cas précédent.
Free Programming Resources
  • _Leo_
  • Proficient
  • Proficient
  • Avatar de l’utilisateur
  • Inscription: Fév 17, 2004
  • Messages: 279
  • Loc: Buenos Aires, Argentina
  • Status: Offline

Message Mars 2nd, 2004, 6:07 pm

Eh bien, vous avez la ligne " #if (REQUEST_METHOD () eq "GET") ", a commenté, puis le" elsif "état n'a pas de sens. Vous devez le changer de" si "ou vous devez décommenter l'partir" si "condition.

Vous devez essayer d'utiliser l'indentation précis dans le texte plus facile de trouver des erreurs.
  • _Leo_
  • Proficient
  • Proficient
  • Avatar de l’utilisateur
  • Inscription: Fév 17, 2004
  • Messages: 279
  • Loc: Buenos Aires, Argentina
  • Status: Offline

Message Mars 2nd, 2004, 6:13 pm

Code: [ Select ]
#!/usr/bin/perl -w

use CGI qw/:standard/;

#print all headers
print header();
print start_html ( "Who is your friend?" );
#Display database content in case of starighforward GET
if (request_method() eq "GET") {
  open FRIENDS ,"friends.dat";
  print "<h3>These are my friends:</h3>\n";
  print"<table> \n " ;
  while ( <FRIENDS> ) {
      chomp ;
      @fields = split / \ | / ;
     
      #Each record will be a self-contained form used for updating records
      print qq~\t<tr>\n~;
      print qq~\t\t<td><form method="POST" action="/cgi-bin/firends.cgi"> \n~ ;
      print qq~\t\t\t$fields[1] - $fields[2]\n~ ; 
      print qq~\t\t<td><input type="submit" value="Change" name="submit">~;
      print qq~<input type="hidden" name="key" value="$fields[0]">\n~;
      print qq~</form> \n~;
    }
    print "</table> \n";
}
elsif (request_method() eq "POST") {
  if (param('submit') eq "Change" ) {
   open FRIENDS,"friends.dat";
   
   print "<h3>Changing record </h3>";
   print qq~<form method="POST" action="/cgi-bin/friends.cgi"> \ n~;
   while (<FRIENDS>) {
     @fields = split / \ | / ;
   
     #This tries to locate the desired record
     if ($fields[0] eq param('key')) {
         #print the chosen record in editable text boxes
         #everything except the product ID number is editable
         print qq~Name:<input type="text" name="name" value=$fields[1]" ><br>\n~;
         print qq~Phone: <input type="text" name="phone" value=$fields[2]" ><br>\n~; 
         print qq~<input type="hidden" name="key" value="$fields[0]" ><br>\n~;
         print qq~<input type="submit" name="submit" value="Save" > \n~;
        
         last;
     }
   }
   print "</form> \n" ;
  }
  else {
   #Open the database for exclusive read and write access
   open FRIENDS , " + <friends.dat" ;
   flock (FRIENDS,2);

   #Create a temporary file for updates and lock it
   open TEMP,"temp.dat";
   Flock (TEMP,2);

   while (<FRIENDS>) {
     @fields = split / \ | / ;
    
     #Create a temproray image of the databse with the updated record
     if ($fields[0] eq param('key')) {
      #Replace the edited record with the updated content
      print TEMP param( 'key' ) .  " | ". param( 'name' ) . " | " . param ( 'phone' ) . "\n";
     }
     else {
      #All "other" records are processed unchanged
      print TEMP $_;
     }
   }
   #Overwrite the previous database with the updated version
   unlink "friends.dat";
   rename "temp.dat", "friends.dat";

   print"<h3>information saved!</h3>";

   close TEMP;
  }
}

#finish-up and cleanup
print end_html( );
close FRIENDS;
  1. #!/usr/bin/perl -w
  2. use CGI qw/:standard/;
  3. #print all headers
  4. print header();
  5. print start_html ( "Who is your friend?" );
  6. #Display database content in case of starighforward GET
  7. if (request_method() eq "GET") {
  8.   open FRIENDS ,"friends.dat";
  9.   print "<h3>These are my friends:</h3>\n";
  10.   print"<table> \n " ;
  11.   while ( <FRIENDS> ) {
  12.       chomp ;
  13.       @fields = split / \ | / ;
  14.      
  15.       #Each record will be a self-contained form used for updating records
  16.       print qq~\t<tr>\n~;
  17.       print qq~\t\t<td><form method="POST" action="/cgi-bin/firends.cgi"> \n~ ;
  18.       print qq~\t\t\t$fields[1] - $fields[2]\n~ ; 
  19.       print qq~\t\t<td><input type="submit" value="Change" name="submit">~;
  20.       print qq~<input type="hidden" name="key" value="$fields[0]">\n~;
  21.       print qq~</form> \n~;
  22.     }
  23.     print "</table> \n";
  24. }
  25. elsif (request_method() eq "POST") {
  26.   if (param('submit') eq "Change" ) {
  27.    open FRIENDS,"friends.dat";
  28.    
  29.    print "<h3>Changing record </h3>";
  30.    print qq~<form method="POST" action="/cgi-bin/friends.cgi"> \ n~;
  31.    while (<FRIENDS>) {
  32.      @fields = split / \ | / ;
  33.    
  34.      #This tries to locate the desired record
  35.      if ($fields[0] eq param('key')) {
  36.          #print the chosen record in editable text boxes
  37.          #everything except the product ID number is editable
  38.          print qq~Name:<input type="text" name="name" value=$fields[1]" ><br>\n~;
  39.          print qq~Phone: <input type="text" name="phone" value=$fields[2]" ><br>\n~; 
  40.          print qq~<input type="hidden" name="key" value="$fields[0]" ><br>\n~;
  41.          print qq~<input type="submit" name="submit" value="Save" > \n~;
  42.         
  43.          last;
  44.      }
  45.    }
  46.    print "</form> \n" ;
  47.   }
  48.   else {
  49.    #Open the database for exclusive read and write access
  50.    open FRIENDS , " + <friends.dat" ;
  51.    flock (FRIENDS,2);
  52.    #Create a temporary file for updates and lock it
  53.    open TEMP,"temp.dat";
  54.    Flock (TEMP,2);
  55.    while (<FRIENDS>) {
  56.      @fields = split / \ | / ;
  57.     
  58.      #Create a temproray image of the databse with the updated record
  59.      if ($fields[0] eq param('key')) {
  60.       #Replace the edited record with the updated content
  61.       print TEMP param( 'key' ) .  " | ". param( 'name' ) . " | " . param ( 'phone' ) . "\n";
  62.      }
  63.      else {
  64.       #All "other" records are processed unchanged
  65.       print TEMP $_;
  66.      }
  67.    }
  68.    #Overwrite the previous database with the updated version
  69.    unlink "friends.dat";
  70.    rename "temp.dat", "friends.dat";
  71.    print"<h3>information saved!</h3>";
  72.    close TEMP;
  73.   }
  74. }
  75. #finish-up and cleanup
  76. print end_html( );
  77. close FRIENDS;
  • phpSelectah
  • Student
  • Student
  • Avatar de l’utilisateur
  • Inscription: Fév 11, 2004
  • Messages: 97
  • Status: Offline

Message Mars 2nd, 2004, 8:03 pm

perles absence d'un interrupteur fonction conduit à un code illisible encore, lol.


:lol:
  • nuclei
  • Graduate
  • Graduate
  • Avatar de l’utilisateur
  • Inscription: Sep 12, 2003
  • Messages: 147
  • Loc: On a mountain
  • Status: Offline

Message Mars 2nd, 2004, 9:58 pm

il est parfaitement lisible. son erreur est de cette ligne

#if (REQUEST_METHOD () eq "GET")


il ne peut pas appeler un elsif s'il utilise le départ si

assez simple pour n'importe qui qui sait plus que php :P
  • phpSelectah
  • Student
  • Student
  • Avatar de l’utilisateur
  • Inscription: Fév 11, 2004
  • Messages: 97
  • Status: Offline

Message Mars 2nd, 2004, 10:16 pm

nuclei a écrit:
il est parfaitement lisible. son erreur est de cette ligne

#if (REQUEST_METHOD () eq "GET")


il ne peut pas appeler un elsif s'il utilise le départ si

assez simple pour n'importe qui qui sait plus que php :P


LOL!


Je ne voulais pas dire qu'il était complètement illisible, il pourrait regarder beaucoup mieux avec "switch", plus linéaire.

google a écrit:
perl est internet yiddish



En sh, je peux comprendre l'aide de if / else / elsif jusqu'à l'éternité, mais perl vraiment fait une erreur de l'exclusion de la construction d'un passage de son stock installer.
;)

Je perl programme à temps plein, de sorte que vous mai note que certains de mes commentaires à ce sujet ne sont kinda.... je ne sais quois puce assed ;)
  • nuclei
  • Graduate
  • Graduate
  • Avatar de l’utilisateur
  • Inscription: Sep 12, 2003
  • Messages: 147
  • Loc: On a mountain
  • Status: Offline

Message Mars 2nd, 2004, 10:19 pm

phpSelectah a écrit:
nuclei a écrit:
il est parfaitement lisible. son erreur est de cette ligne

#if (REQUEST_METHOD () eq "GET")


il ne peut pas appeler un elsif s'il utilise le départ si

assez simple pour n'importe qui qui sait plus que php :P


LOL!


Je ne voulais pas dire qu'il était complètement illisible, il pourrait regarder beaucoup mieux avec "switch", plus linéaire.

google a écrit:
perl est internet yiddish



En sh, je peux comprendre l'aide de if / else / elsif jusqu'à l'éternité, mais perl vraiment fait une erreur de l'exclusion de la construction d'un passage de son stock installer.
;)

Je perl programme à temps plein, de sorte que vous mai note que certains de mes commentaires à ce sujet ne sont kinda.... je ne sais quois puce assed ;)


malheureusement, il ne faut I. Je suis en train de sortir de codage tho :P

Afficher de l'information

  • Total des messages de ce sujet: 10 messages
  • Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 170 invités
  • Vous ne pouvez pas poster de nouveaux sujets
  • Vous ne pouvez pas répondre aux sujets
  • Vous ne pouvez pas éditer vos messages
  • Vous ne pouvez pas supprimer vos messages
  • Vous ne pouvez pas joindre des fichiers
 
 

© 2011 Unmelted, LLC. Ozzu® est une marque déposée de Unmelted, LLC