473,372 Members | 1,550 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,372 software developers and data experts.

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 2176
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,509 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,509 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,509 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

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

Similar topics

1
by: sam | last post by:
I have a function writen in Perl that takes a name-value list (array) as argument and returns a name-value list (array). My question is: How to call this function from PHP and get the returned...
1
by: Wet Basement | last post by:
I am passing data to a putcart.pl , parsing it, then building the query string to put the item in the shopping cart: $cartStr =...
1
by: Mavis | last post by:
Hi, I'm trying to use a simple form to select by which column I will display output from a MySQL database. I'd like to display based on ORDER BY and select Written, Average, etc. I know the...
7
by: Danny | last post by:
Newbie here Thanks for the help with this command: print "Status: 204 No Content\n\n"; which returns nothing in a perl script. This is great because I just want my perl script to increment a...
7
by: AznCollegeGuy | last post by:
Hello, Im trying to invoke a simple perl script with in my visual c++ gui program to with c++'s system call feature: when i call: system("dir"); it works
7
by: Wladimir Borsov | last post by:
I want to call a perl script myscript.pl in my cgi-bin from a HTML web page. This call should NOT use SSI (because in this case HTTPS://.... protocol is necessary). Furthermore NO button click...
3
by: soniamadtha | last post by:
Hello everyone i have the following script (extract.pl) #!/usr/bin/perl # Purpose : This Program is used to extract only the stocklist from the input string #use warnings; scalar @ARGV...
4
by: jane007 | last post by:
Hello everybody: I am having a problem. On Unix platform, there is a script that need user to input data from console, then when I call Unix perl script from Windows, these is an issue occurs,...
1
by: houh | last post by:
I have a java app that generates openoffice docs. When I run the java app in a shell script, as: export JAVA_HOME=/opt/corp/projects/metrics/Java/jdk1.5.0_07/bin/java export...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.