469,319 Members | 2,338 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,319 developers. It's quick & easy.

Getting an if statement to call in a PERL script

Hello all. I need to get a html page to work with a PERL script

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
  4. <head>
  5. <title>If's in PERL </title>
  6. </head>
  7. <body>
  8.  
  9.  
  10. <form name = "if" method = "post" action = "https://outranet.scm.tees.ac.uk/users/d4028307/august/hwp/filetest.cgi">
  11. <input type = "text" name = "spinach">
  12. <input type = "submit" value = "Send Script">
  13. <input type = "reset" value = "Reset">
  14. </form>
  15.  
  16. </body>
  17. </html>
  18.  

This is the PERL script i want to use. However when i try it in my browser all I get is an internal server error. What am i missing, Can anyone help? Thank you.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use CGI;
  4.  
  5. my $food;
  6.  
  7. $food = CGI::param ('spinach');
  8.  
  9. if ($food eq 'spinach')
  10. {
  11.     print ('Spinach is good for you  so you get dessert')
  12. }
  13. else
  14. {
  15.     print ('you don't get dessert');
Aug 2 '07 #1
8 1865
miller
1,089 Expert 1GB
Add "use strict;" to your cgi script, and make sure to run it from the command line to test the syntax.

If you look at the newly formatted post above, it should be fairly obvious what the problem is though.

- Miller
Aug 2 '07 #2
numberwhun
3,503 Expert Mod 2GB
First, just a note, when you are doing your code tags, the format inside of the square brackets is code=language. I am hopeful that our friendly neighborhood moderator, Miller, will see that and correct it for you. ;-|)

As for your issue, do you have CGI configured with your web server? You may want to read the tutorial on configuring apache (if that is what you are using). If your web server isn't configured for CGI, then the script won't be run. On the other hand, if it is, are you putting the cgi script in the correct location? Your CGI configuration would dictate where you put your scripts.

Other than that, could you please post the error(s) that you are seeing as well?

Regards,

Jeff
Aug 2 '07 #3
The whole PERL thing is kinda confusing to me anyway. I hear its best used on a Linux machine but I use Windows XP. I started learning it at university but i'm really struggling.

You talked about a command line interface for PERL what can you recommend?

Hate to be vague but i have a complete assignment to do lol (this code is not part of it) and i'm still really just a beginner. :-)
Aug 2 '07 #4
numberwhun
3,503 Expert Mod 2GB
Miller was refering to running the script from the command line to see if everything runs ok. By running it from the command line, you will see the errors that are outputted that you wouldn't see if you automated it say, but having it run from a website or scheduler.

Regards,

Jeff
Aug 2 '07 #5
KevinADC
4,059 Expert 2GB
The reason it fails as a CGI is that there is no http header being printed. But it will work as a command line script if there are no other errors in the code.
Aug 2 '07 #6
DDragon
15
Hello all. I need to get a html page to work with a PERL script

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
  4. <head>
  5. <title>If's in PERL </title>
  6. </head>
  7. <body>
  8.  
  9.  
  10. <form name = "if" method = "post" action = "https://outranet.scm.tees.ac.uk/users/d4028307/august/hwp/filetest.cgi">
  11. <input type = "text" name = "spinach">
  12. <input type = "submit" value = "Send Script">
  13. <input type = "reset" value = "Reset">
  14. </form>
  15.  
  16. </body>
  17. </html>
  18.  

This is the PERL script i want to use. However when i try it in my browser all I get is an internal server error. What am i missing, Can anyone help? Thank you.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use CGI;
  4.  
  5. my $food;
  6.  
  7. $food = CGI::param ('spinach');
  8.  
  9. if ($food eq 'spinach')
  10. {
  11.     print ('Spinach is good for you  so you get dessert')
  12. }
  13. else
  14. {
  15.     print ('you don't get dessert');

Ok I'm not sure if it has not been noticed (I'm sure it must have) but first of all i can see on the second last line
Expand|Select|Wrap|Line Numbers
  1. print ('you don't get dessert');
the script is calling the "talking marks" in front of "you" and in the word "don't" as one section and making the rest another thats where one error is, and as I'm new to the Perl/CGI scripting scene I'm not sure but I've been taught to put
Expand|Select|Wrap|Line Numbers
  1. use CGI ':standard';
into scripts that are being called by the web browser tho i might have that the wrong way around :S, also there is a ; missing after the line
Expand|Select|Wrap|Line Numbers
  1. print ('Spinach is good for you  so you get dessert')
i don't know if i missed any other errors but thats what i can see from my skill level

-- DD

-= "In a world the doesn't comprehend" =-
Aug 8 '07 #7
numberwhun
3,503 Expert Mod 2GB
Instead of:

Expand|Select|Wrap|Line Numbers
  1.      print ('you don't get dessert');
  2.  
why not use:

Expand|Select|Wrap|Line Numbers
  1.      print ("you don\'t get dessert");
  2.  
The main difference between the single and double quotes is that you don't get interpolation of variables. Plus, when you need a single quote, as in "don't", you cannot escape it as single quotes don't allow anything to interpolate or escape. They put to the screen exactly what you type. So, when you put the single quote in don't in, it saw it as the end of that section of input.

Regards,

Jeff
Aug 8 '07 #8
KevinADC
4,059 Expert 2GB
cgi script need to print a header. Look in the cgi.pm documentation for details.
Aug 8 '07 #9

Post your reply

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

Similar topics

1 post views Thread by sam | last post: by
1 post views Thread by Mavis | last post: by
7 posts views Thread by AznCollegeGuy | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.