Hello, I am working on a homework assignment and I can't seem to get the Perl script to run off the server. This is my first time working with Perl, but I'm fairly comfortable with HTML. I've tried debugging and I've checked it out using OptiPerl, which show it just fine. Also, I've been searching for a tutorial on this for about 8 hours now. If someone knows where I can find a tutorial on this, it'd be much appreciated. I'm supposed to use the POST method and I'm not supposed to use CGI. I'll post both of my files here, so I'm apologizing now for being a bit long. My HTML script:
<html> <head></head> <body> <form action="/cgi-bin/hw4.pl" method="POST"> <br><br><br> <center><p>Please enter the following data:</p> <br> <table border=0><tr><td>First Name:</td> <td> <input type="text" name="first"></tr> <tr><td>Last Name:</td> <td> <input type="text" name="last"></tr> <tr><td>Age:</td> <td> <input type="text" name="age"></tr> <tr><td>Favorite Color:</td> <td> <input type="text" name="color"></tr> <tr> <td colspan=2><center><input type="submit"></center></td></tr> </table></center></form> </body> </html>
My Perl script:
#! /usr/local/bin/perl -w use strict; $buffer = $ENV{'QUERY_STRING'}; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $FORM{$name} = $value; } print "Content-type:text/html\n\n"; print "<html><body>"; print "<center>"; print "<h2>Your Data:</h2>\n"; foreach $name (keys(%FORM)) { print "$name = $FORM{$name}<br>"; } print "</center>"; print "</body></html>";
Update: I don't know if anyone will check this again, but I thought I'd comment to everyone here. Thanks to all of you for your comments. This is my first Perl assignment in this class, and for that matter, ever. I have updated my code to what suggestions that I received and what I realized I didn't do linearly. However, I still get the same errors, where that debugger says that most of my variables require an explicit package name. I'm sorry I assumed everyone would know that is what would happen. I don't really understand what that means, unfortunately. Update Again: After scouring the Perl help files, I found my bane, which actually happened to be the word "my." How come I never learned that I'd have to use that, in class? Seems like something awefully important to gloss over! Is a "my" statement usually necessary when declaring your own variables? Well, thanks again to all of you who have commented! ^_^ <--happy n00b

In reply to Trouble getting a Perl script to run with an HTML form by alarthame

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.