| Welcome to Webforumz.com. |
|
Jul 20th, 2007, 11:35
|
#1 (permalink)
|
|
New Member
Join Date: Jul 2007
Location: Ireland
Age: 17
Posts: 2
|
A perl n00b needs your help!
 <--The sheep's perdy cool ain't it? I like these forums..
Hi, I'm a n00b to this website so I'm sorry if I'm posting in the wrong place and please don't murder me! My problem is I have a form and am trying to use perl to submit/post/send it. But every time I did this I got a 405 error. Since then I've been on some other sites and forums and found a line to insert into my .htaccess file (It's Options ExecCGI). That seems to have solved the preliminary problem but now I have a new one in that fire fox displays a message saying: Firefox has detected that the server is redirecting the request for this address in a way that will never complete. Not only am I a n00b to these forums but I'm also one to perl, I have beside me an O'Reilly book on CGI programming (the one with the rat on it) and so far I'm still on the first post example in it. It's only a little greeting! I feel so stupid having to ask you lot with something so small! I don't see how I'm going to get the advice/learn otherwise, I'm the only one in the office with any knowledge of web design (Trying to sort out the companies website).
If it makes much difference the site's on a linux server and I'm using a mac (without dreamweaver, this would be so much easier if I had dreamweaver!) so I'm hard coding with pagespinner (the trial version).
Thanks guys (and gal's o' course) your advice is really needed!
|
|
|
Jul 20th, 2007, 12:22
|
#2 (permalink)
|
Join Date: May 2006
Location: North West, UK
Age: 21
Posts: 1,389
|
Re: A perl n00b needs your help!
You're very brave. Perl isn't an easy language. I had a little go a little while back and ended up frustrated big time. Same happened for me with ruby I got the pragmatic programmers guide and got lost withing a few pages.
A form would be very simple (and I mean disgustingly so) with php. A very simple one could be done with a few lines of code.
Here is a free mac text editor specifically designed for coding etc.
TextWrangler
Pete. 
|
|
|
Jul 20th, 2007, 12:28
|
#3 (permalink)
|
|
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 65
|
Re: A perl n00b needs your help!
If you posted the code you are trying to use it would greatly help. 
|
|
|
Jul 20th, 2007, 12:29
|
#4 (permalink)
|
Join Date: May 2006
Location: North West, UK
Age: 21
Posts: 1,389
|
Re: A perl n00b needs your help!
Don't tell me you're a perl whizz as well? Is there anything you can't do?
Pete. 
|
|
|
Jul 20th, 2007, 13:05
|
#5 (permalink)
|
|
New Member
Join Date: Jul 2007
Location: Ireland
Age: 17
Posts: 2
|
Re: A perl n00b needs your help!
Thanks for the mac text editor link, I'll go have a look at it as soon as I've finished posting.
Really? That would be fantastic, we need a quick fix down here asap to get the form online, can't have customer's going to dead links can we? I wanted to learn php more than I did perl but, alas, there were no books to be found in my house on php. I was going to try a code which would make sure all the fields had something in them, I saw something like I was looking for on a site yesterday but going to the url of the perl file like I usually do with html and css pages wasn't working.. But that'll at least take a solid weekend to figure and that's <i>after</i> I know what I'm doing.
I definetly want to continue learning perl though. No question to that, I hate leaving things unfinished or unresolved (they give me nightmares).
And of course you'll need the code to figure out what's wrong! Silly me, sorry. This is the quick greeting code though, ('Quick' my left big toe, it's taken me the morning to type it out and since then I've been trying to fix it.) but if I knew what was wrong with it, I could learn from it.
Without further ado, here's the code:
#!/usr/local/bin/perl
$webmaster = "info\@selprint\.com";
&parse_form_data (*simple_form);
print "Content-type: text/plain", "n/n";
$user = $simple_form{'user'};
if ($user) {
print "Nice to meet you ", $simple_form{'user'}, ".", "\n";
print "Please don't eat the bread!", "\n";
} else {
print "You didn't enter a name, perhaps you haven't any fingers?", "\n";
print "Poor you, you sould try and see if you can get some bionic ones or something..", "\n";
}
exit(0);
sub parse_form_data
{
local (*FORM_DATA) = @_;
local ( $request_method, $query_string, @key_value_pairs,
$key_value, $key, $value);
$request_method = $env{'request_method'};
if ($request_method eq "get") {
$query_string = $env{'query_string'};
} elseif ($request_method eq "post") {
read (stdin, $query_string, $env{'content_length'});
} else {
&return_error (500, "Server Error",
"Server uses unsupported method");
}
@key_value_pairs = split (/&/, $query_string);
foreach $key_value (@key_value_pairs) {
($key, $value) = split (/=/, $key_value);
$value =~ TR/+/ /;
$value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg;
if defined($FORM_DATA{$key})) {
$FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value);
} else {
$FORM_DATA{$key} = $value;
}
}
}
sub rturn_error
{
local ($status, $keyword, $message) = @_;
print "Content-type:text/html', "\n";
print "Status: ", $status, " ", $keyword, "\n\n";
print<<End_of_Error;
<ttitle> CGI Program - Unexpected Error</title>
<h1>$keyword</h1>
<hr>$message</hr>
Please contact $webmaster for more information.
End_of_Error
exit(1);
}
|
|
|
Jul 20th, 2007, 18:41
|
#6 (permalink)
|
|
Up'n'Coming Member
Join Date: Sep 2006
Location: UK
Posts: 65
|
Re: A perl n00b needs your help!
@Pete: No I'm not very good with perl but it is similar to many programming languages. It's like learning an instrument. Once you learn one, you know how to read the musical notation, so learning another is considerably easier.
Same goes with most programming languages because they are all similar.
So in that sense, I can kind of tell what is happening and see if anything seems illogical.
Then I can ask Master Google for his advice.
@IchigoFork:
Quote:
|
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
|
This suggest something is wrong with the HTTP headers.
Try this:
change the fourth line from:
- Code: Select all
print "Content-type: text/plain", "n/n";
to:
- Code: Select all
print "Content-type: text/plain", "\n\n";
|
|
|
| Thread Tools |
|
|
| Rate This Thread |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|