Re: Passing Arguments With Perl/Cgi
by chromatic (Archbishop) on Mar 19, 2000 at 00:25 UTC
|
Use CGI -- the standard module for CGI programming. Getting a parameter is as easy as:
my $value = $cgi->param('value'); | [reply] [d/l] |
Re: Passing Arguments With Perl/Cgi
by Anonymous Monk on Mar 19, 2000 at 01:04 UTC
|
Never mind! I did a lot of searching (A LOT!) and found the answer for myself.
After sitting in a chat room for nearly an hour, I got my answer:
@pairs = split(/&/, $ENV{'QUERY_STRING'});
foreach $pair (@pairs) {
local($name, $value) = split(/=/, $pair);
#That code that changes + to spaces and all the other characters... (w
+hich I know)
}
THERE: now I can simply get a value by calling this code:
$TheVariable = $name{'TheVariableFromTheForm'};
I Hope this might help anyone else who has this same question... | [reply] [d/l] |
Re: Passing Arguments With Perl/Cgi
by justinNEE (Monk) on Mar 19, 2000 at 08:03 UTC
|
No No No, listen to chromatic and the others. :) use CGI; It may be uncomfortable using modules, but it IS neccesary for two reasons: 1> no need to reinvent the wheel EVERYDAY for the rest of your life, and 2> you are not at a point where you will right BETTER code than in the modules. One of the most attractive features of the Perl universe is that there are always smarter people out there willing to "hook you up". (= but since I know you won't listen to what I just typed, this will be useful:
$stringNEE=~s/%(..)/pack("c",hex($1))/ge;
$stringNEE=~s/+/ /g;
| [reply] [d/l] |
|
while it may be necessary and uncomfortable to use other peoples code, i do belive that it is a good idea to know what the code you are using is doing. When I first used modules I was completely unfamiliar with what I was doing with them, I was just using regurgitations of what other people had done. when I realised what the area of the module that I used a lot did, I became more (ahem)enlightened(sorry.) to what the uses of perl were. so, by questioning the module and asking/researching what it was doing in certain stages I could develop a greater understanding of the language. BTW, I am a fairly extensive module user, but I still sit down and research what one will be doing if I use it a lot.
| [reply] |
|
That last one should be:
$stringNEE =~ tr/+/ /;
(It's a LOT faster to use tr/// than s///g.)
| [reply] [d/l] |
Re: Passing Arguments With Perl/Cgi
by turnstep (Parson) on Mar 24, 2000 at 23:46 UTC
|
(It's very important to know how to do it yourself.)
Here's my way to do it. Note how it catches invalid
pairs.
if ($ENV{'REQUEST_METHOD'} eq "GET") {
for (split(/\&/, $ENV{'QUERY_STRING'}) {
if (($name, $value) = /(.*)=(.*)/) { ## Normal
$value =~ ## Unescape $value here
}
else { ## Abnormal, no "equal"!
$name =$_; $value=0;
}
$name =~ ## unescape $name here
}
Update:Yes, I know, you should
just use CGI. The above code is
merely for educational purposes, please use CGI
for any "real" code. :)
| [reply] [d/l] |
|
Presuming your code isn't on a home personal enviroment in a lot of cases it simply isn't practical to use modules. In the case of code used on a 1000 machines say.
| [reply] |
|
| [reply] |
Re: Passing Arguments With Perl/Cgi
by Anonymous Monk on Mar 18, 2000 at 22:46 UTC
|
Post = STDIN Command
Get = ???? | [reply] |
Re: Passing Arguments With Perl/Cgi
by Anonymous Monk on Mar 19, 2000 at 00:48 UTC
|
Thanx, but what I want is the actual code to do it myself, not a module that does it for me, so any more help is welcome! | [reply] |
|
| [reply] |