View Full Version : PERL Question
Digger3000
02-12-2005, 11:38 PM
First I'll say that I am very, very, very new at using this programming language. Anyway I'm trying to make a PERL script that I can use to submit data from a form. But what is the variable to put the input into the PERL script?
mlseim
02-12-2005, 11:47 PM
Digger,
Look at the very bottom of this post ...
http://www.codingforums.com/showthread.php?t=51979
You'll see that you need an HTML webpage with the
variables named. Then, you'll see the Perl script that
takes in the same variable names from the form.
... and have you ever installed a Perl script before?
if not, you might want to view some tutorials on the
internet. Search Google for simple Perl tutorials.
Digger3000
02-13-2005, 12:09 AM
I am very, very, very new at using this programming language.
I have installed a script, but not with variables.
Digger3000
02-13-2005, 12:14 AM
Ok, can someone tell me what this is: "Undefined subroutine &main::param called at helloperson7.pl line 2. "
mlseim
02-13-2005, 02:27 AM
I think you had better start out with something simpler and
also look at some Perl tutorials on the internet.
You will really be frustrated using this forum as a tutorial.
You mentioned a script called: helloperson7.pl ?
We have no idea what that is ... :confused:
I already pointed you to an easy, simple, no-frills HTML form
with a Perl script to email the form information. If you can't
get that to work, you had better read some tutorials first.
It doesn't get any more basic than that.
But I really do recommend learning Perl and/or PHP. It will
benefit you immensely in your web development projects.
Digger3000
02-16-2005, 11:52 PM
I really don't have time to read through tutorials. I came here to talk to real people, now can you just please tell me what to do?
mlseim
02-17-2005, 12:15 AM
OK,
First I'll say that I am very, very, very new at using this programming language
First, do you have any Perl scripts installed that work?
I'm going to establish that you've installed scripts in the
past and those work, it's just the one called, helloperson7.pl
that is not working?
Some things we assume you already did:
1) you uploaded the script in ASCII mode (not binary mode)
2) you set permissions on the script: CHMOD 755
Let's start out there and see where you're at ...
Digger3000
02-17-2005, 12:45 AM
Ok, the only script I've installed is the "Hello World" one.
1) I don't think I had a choice in uploading mode.
2) Do I need to type that somewhere?
mlseim
02-17-2005, 02:39 AM
The FTP program has a selection on it (depends on which program you
use). But if your script worked OK, then you did it right.
Next,
Do you already have a form made (an HTML form)?
Can you post it or give us a link.
We need to see the form in order to see your variables used.
and ... save your script "helloperson7.pl " as a .txt file and
attach it to a post so we can see that too.
Digger3000
02-17-2005, 02:54 AM
I don't have an FTP program, I just uploaded it on tripod. The form code looks like this.
<HTML>
<HEAD>
<TITLE>Template</TITLE>
</HEAD>
<BODY>
<form name=a action="http://jcers.tripod.com/cgi-bin/helloperson7.pl" method=POST><CENTER><input type=text name="b" size=20><BR><input type=submit></CENTER>
</BODY>
</HTML>
and the PERL script, so far, looks like this.
#! /usr/bin/perl
my $name=param('b');
print "Content-type: text/html\n\n";
print "<body><font size=7>Hello $name!";
print "</font></body>";
mlseim
02-17-2005, 12:51 PM
#! /usr/bin/perl
use CGI ':standard'; #<-- this was the line you were missing.
my $name=param('b');
print "Content-type: text/html\n\n";
print "<body><font size=7>Hello $name!";
print "</font></body>";
Digger3000
02-17-2005, 10:37 PM
I changed the PERL code, it now looks like this:
#! /usr/bin/perl
use CGI ':standard';
my $name=param('b');
print "Content-type: text/html\n\n";
print "<body><font size=7>Hello $name!";
print "</font></body>";
And I got this error:
Your script produced this error:
Can't locate CGI.pm in @INC (@INC contains: . / /lib /site_perl) at helloperson10.pl line 2.
BEGIN failed--compilation aborted at helloperson10.pl line 2.
mlseim
02-18-2005, 12:42 AM
That might explain a lot of your problems.
Your webhost's Perl version might be old and it doesn't support
some of the more common modules. You're quickly running out
of options, other than "canning" your existing host and switching
to a host that has a modern up-to-date server.
Try the Perl script below .... it might work or not :confused:
==================================================
#! /usr/bin/perl
&parse_form;
my $name = $input{'name'};
print "Content-type: text/html\n\n";
print "<body><font size=7>Hello $name!";
print "</font></body>";
###### Read in Variables from Form #########
sub parse_form {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 5) {
$buffer = $ENV{QUERY_STRING};
}
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/'//g;
$input{$name} = $value;
}
}
Digger3000
02-18-2005, 12:58 AM
I found the problem! I didn't (know that I had to) upload CGI.pm to my cgi-bin folder. Now it works!
mlseim
02-18-2005, 03:14 AM
Great!
Not everyone has to have that file in their cgi-bin...
It just depends on the server.
Glad you got it to work.
vBulletin® v3.8.2, Copyright ©2000-2010, Jelsoft Enterprises Ltd.