[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] Mac CGI-to-Unix answer



First I'd like to thank everyone who took the time to help me on this problem.
A little background:
What I'd been trying to do was port a MacPerl CGI to Unix. The script was
designed to take input from a form type (pull down menu) and return a url.
It worked sweet on my Mac. I used cgi-lib to parse the form on the mac, and
used the input with an associative array to come up with the url.
When it got to the Unix box, there were all sorts of problems, finally
ending with a page that not only didn't do anything, but generated no
error.
Well, I finally got our consultant to the site and, with some fiddling, the
script is working well. Here it is, followed by some comments on what to
watch out for:

#!/usr/bin/perl

%try = (
"input1", "Location: http://www.location.com/location1.html\n\n",
"input2", "Location: http://www.location.com/location2.html\n\n",
"input3", "Location: http://www.location.com/location3.html\n\n",
"input4", "Location: http://www.location.com/location4.html\n\n",
"input5", "Location: http://www.location.com/location5.html\n\n"
);

MAIN: {
unshift (@INC, "/usr/www/cgi-bin/requires");
require ("/usr/www/cgi-bin/requires/parse_form.pl");

&parse_form;

print "$try{$form{'url'}}";
}

First thing I've learned is: Sit down with whoever is setting up the server
and make them go over everything they do in terms of the cgi-bin dir. In
our case, when our man finally came in, I watched as he set up cgi-bin in
such a way that whatever was placed inside it was considered to
automatically be a script. He also made the requires directory to hold any
libraries. The "parse_form.pl" does the same thing as cgi-lib - it returns
the data submitted from a post or get command in the array form.
Then, make the person test scripts on the box. It's the only way to be sure
that the machine is working correctly.
Some other tips:
If you want to use public-domain libraries, try to download them directly
from the your source to the unix box. My cgi-lib still doesn't work on the
unix box, and I'm not sure why.
Our server guy recommends using the extension ".pl" instead of ".cgi". It's
a unix thang. It works.
To make things easier, try saving your script using something like
BBEdit.lite, something that enable you to "save as" with Unix line breaks.
All my html and perl stuff, if I needed to work on it, would open as one
line with a bunch of machine code where the break lines were supposed to
be.

That's what I know. Now what I don't know. I'm not sure I understand what
this line does:
unshift (@INC, "/usr/www/cgi-bin/requires");


Can someone explain what it's doing.? I have a vague idea from the camel
book, but not a good clue. There is no mention of @INC in the
parse_form.pl. I know it'ss some kind of local thing. I just want to
understand what it does.

Thanks, Tim