'

Using perl with RH and apache

you might be better off not trying to re-invent the wheel - have you looked for applicable software, like phorum, that would let you do more of what youwant with less effort?

Dear Bloggie:

Problem #1: The musicians recently had a camp out for jamming, but mostly eating. Our normal approach is to take a hard copy sign up sheet to a weekly class and obtain volunteers for chili, salad, drinks, etc. It would be much easier if the musicians could simply sign up on their web site. Enter PERL CGI.

Back shortly after the Wright Brothers were flying (I may have been holding the fire bottle) I became a cracker jack FORTRAN and BASIC programmer. I was hopeless with C and C++ (started using profanity around pointers), but really like what I see in PERL and its ability to be used to create interactive web pages. I have installed, written PERL code and run it on my Windows machine.

Could you mention the procedure for installing and using PERL in the Apache - Redhat environment? I'll be using cgi.pm. If I can get an elementary PERL CGI script to execute from an example web page, I'll be able to expand that to the food sign-up sheet.

Problem #2: I would like to allow the musicians to provide e-mail feedback on a web page, but when I saw a friends set up was disappointed to see that the feedback received from her script had a large amount of strange characters. You could pick out the content, but it would be nice if it looked more like what was typed as feedback. I hope this makes sense. I'm assuming this was either a feature or limitation of PERL?

Signed:
in search of a pointer

For most people there is no magic procedure to installing PERL for Apache on Linux - it's just there to do with as you wish. There is one for high volume users - you need to be sure the applicable Apache 2 modules are installed and set up your directory tree carefully; but since you're not planning on high volume work, you should just go with what's there by default.

Your apache httpd.conf file will tell you where the cgi directory is:

ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"

You can find out where Perl is by using "% which perl" on the command line, or if that doesn't work try

% find / -name perl -print |& grep -v cannot

or what ever works in the shell of your choice (I use csh)

Put the location info for the perl variant you want to use in the first line of your script:

#!/usr/local/bin/perl
rest_of_your_script

Put the script in $ScriptAlias, set permissions so apache can read and execute the script, and start your HTML form def with:

<FORM ACTION=/cgi-bin/my_script.pl METHOD=POST ENCTYPE=application/x-www-form-urlencoded NAME=my_script>

Now, for question two, I'm guessing that there's a problem in character conversion on post style submissions. Notice that "urlencoded" above? That's not Ascii, so you have to convert to a human readable form before doing anything with arriving data.

I believe there's a slick and generalized solution in CGI.pm but as a practical matter I program in PERL so rarely now that I can never remember the name or syntax needed for the libs and so default to doing simple stuff the simplest possible way - in this by case copying in a bit of script I've used since at least the mid ninties:

if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@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;
$FORM{$name} = $value;
}

Now everything in $FORM is in the right form...

There's much better code around, but this works - and you'll be able to find an equivelent easily enough now that you know what to look for.

On the other hand, you might be better off not trying to re-invent the wheel - have you looked for applicable software, like phorum, that would let you do more of what you want with less effort?