Helpful Information
 
 
Category: Perl/ CGI
CGI Beginner needs Help!

Hi! I'm a beginner at CGI and I'd appreciate some help with the language. I peeked at a few primers and though they were informative, I still have further questions unanswered about some of the code.

From the glances I've had, PERL seems just like any normal language. Doesn't look object oriented and SEEMS even more high level that C++. But I was reading a tutorial from htmlgoodies and it used as its example a guestbook CGI, which emails some form data to the person requesting the data.

Firstly, I understand the first line (which is the directory PERL is under) and I understand the format of "if", "sub", and "print" structures. What I don't understand are the reserved words and some predefined variables.

For instance, the primer said that when you send a form to a CGI script, the entire form comes under the variable $ENV. A question I've had about this is HOW?!? How is it stored in $ENV? I also have the code that supposedly separates out all the elements of $ENV, but I really don't understand much of the syntax.

Also, the print statement. When you are sending email via CGI, how are you sometimes able to write ONTO a form with print while writing the html of a page using another form of print?

The code I'm referring to is located at:
http://www.htmlgoodies.com/primers/perl/guestbookcgi_text.html

It doesn't really matter if you explain THAT particular code, just the basics on how its done and why its so and what some of the symbols mean. Sorry if its a lot to ask, but I'm still waiting for the book I ordered and I need to glean some info so I can produce SOME results soon. Thanks.

Well thats a very simple, neat and good for begginers script, (i like it)

so first, yes perl is a great language ver powerful, sicne it is not only web oriented, fast and with infinite number of add ons,

the $env,
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
# here the script check whether the form was submited via the POST or the GET actions. as you know the GET is the one that shows in the addres bar of your browser, and the POST dosent.

___ read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# now here read the info submited, STDIN ( i think is standard input, not sure) $buffer is where all the info will be stored, and $env, is like a perl action, somehow for sytem things, sing $ENV you can get the users ip, browser and lots of those things.

___ @pairs = split(/&/, $buffer);
# here you create the Array pairs, by spting the input [which looks like this (name=value&name2=value2&name3=value3) the & is a separator for each name and value. so after it is split the info will be stored in the arrary, it would look kind of like this.
@pairs = ('name=value', 'name2=value2', 'name3=value3');


___ 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;
}

# and finally here using the foreach function, which is like a while, that end automatically, divide the name=value, into two different variables, the "=~" are the regex, the first one, changes the + signs with spaces, and the second one, not sure what it does, ill have to check that up.

then you just make a way to call the info, using the $FORM[$name] = $value,

for example if you have a name called "Shoe_size"

you use the print $FORM{Shoe_size} and it will print its value

Hope thats clear,

Calilo

I'll start off by saying I'm more of a C++ programmer than anything else. So, if you're familiar with C++, my "interpretation" might be easier :p .

Ok, so I kind of understand the part where you split the $ENV variable into the final $FORM variable. My new questions now are:

Does the @ symbol in front of a variable mean that that variable will be an array?

Is $FORM, in this case, also an array?

How do arrays work in PERL? I know in C++, you must define the array like:
int array[]; /*or*/ int array[40];
It seems that in PERL, you don't define the array, and you can use an enumeration as the array index??? The code has
$FORM{name}; in it. Is that how you access the array? Or is $FORM even an array? Because you stated before that @pairs was an array.

Thanks for answering my previous question.

Also, would you mind explaining how I can set the path to the PERL I have installed on windows? Unfortunately, everything at my job is run off of Windows, including the server. That means I'm not quite sure of how to set the path correctly. For instance, on Unix, the path is set to:

#!/usr/bin/perl

#theoretical path, but just notice how its written.

How would I set a similar path on a windows host? Say the location on the windows machine is
c:\komodo\perl
and the .exe is under
c:\komodo\perl\bin\perl.exe

Would I do:
#!c:\komodo\perl

well, in perl you dont have to define the arrays and var as C++, the basis are
a varible has to hav the "$" infront, and it cant start with a number,
so everytime you se $something, it will be a variable, and the same goes for and arrays, @something, will always be an array,

2) you have first the @pairs array, but later on you split set a variable $pair, in the foreach (not sure if there is similar function in C++) so the loop will mak $pair have each time a value like this one, value=value. so by using split, you create two different variables, $name and $value,
($name, $value) = split(/=/, $pair);

it creates the variable $name, and assigns whatever is found before the "=" sign, and then vor the variable $value, it assings everything after the "=" sign. the it assings to $form{} the name and value,

$form{} inst an array neither a regular variable, i hardly ever use it so never looked up for the name, but is is like a special varible that can have different nemes each with its corresponding values.

and finally the path to perl should be the exe file

c:\komodo\perl\bin\perl.exe

or wherever it is,

im a mac/unix user, so not sure about windows, but ive seen those paths in some scripts,

Calilo

Thanks for the help.

Youre welcome, anything else you need let us know,

calilo

Well, now that I've got a new question :p

Ok, I'm trying to accomplish a script that e-mails me the contents of a form. I now understand how to split the variables from the $ENV variable. Here's a portion of the code:

open(MESSAGE, "c:/program files/outlook express/msimn.exe");

I've been trying this, thinking that maybe using the outlook process would work out, but it hasn't been working, and frankly, its beginning to frustrate me. The outlook program itself is actually quite complex, and I'm not sure how windows processes function as opposed to unix processes.

My question, however, is if it is possible to open the process from another website. For instance, I know that yahoo has a decently uncomplicated e-mail process. Is it possible to do something like:

open(MESSAGE, "http://mail.yahoo.com");

Also, although this will sound incredibly strange, my high school website has a PHP e-mail page that runs off of PINE (since my school's server runs Unix on its server). Is it possible to open some sort of process that connects to my SCHOOL's server through SSH protocols, opens PINE -t, and then mails the form information to another site in that fashion?

Thanks in advance.

as i said, i dont know much of windows, so about the outlook thing i cant tll you anything,

i think that if you install phpdev in you pc, sendmail, will be installed to, so you probly should check that up,

and about the high school if you could upload a script to their server you could do something to use tehir sendmail, application, but i really yhink that the best thing would be checking the phpdev, and else youll us your perl script in the web, more than in you pc, so you could use a web server for that

Calilo

Thanks.

See New Threat










privacy (GDPR)