CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
URL request captured in a variable

 



rwynn
Deleted

Sep 13, 2000, 11:06 AM

Post #1 of 4 (533 views)
URL request captured in a variable Can't Post

I'm trying to capture the results of a url request in a variable so that I could parse the page and then output.

Any help would be, um, helpful.

Wynn





perlkid
stranger

Sep 13, 2000, 11:52 AM

Post #2 of 4 (533 views)
Re: URL request captured in a variable [In reply to] Can't Post

 
Your not being all that specific but I think you want to read the variables in the url,

Then use this,
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


#############################################
sub parse_form {
my (@pairs, %in);
my ($buffer, $pair, $name, $value);

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
}
else {
&cgierr('You cant run this script from telnet/shell.');
}

PAIR: foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);

$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

($value eq "---") and next PAIR;
exists $in{$name} ? ($in{$name} .= "~~$value") : ($in{$name} = $value);
}
return %in;
}
#############################################
%in =&parse_form;
</pre><HR></BLOCKQUOTE>

Now if in the url you have somthing like this, http://www.site.com/blabla.cgi?test=yes

Then if you do this,

print "$in{'test'}";

then it'l print yes.

Get It?

perlkid


rwynn
Deleted

Sep 13, 2000, 12:26 PM

Post #3 of 4 (533 views)
Re: URL request captured in a variable [In reply to] Can't Post

I think I found what I was looking for. It was the LWP module.

Thanks for your help anyway, perlkid. You're right, my request wasn't specific enough.



perlkid
stranger

Sep 14, 2000, 10:00 AM

Post #4 of 4 (533 views)
Re: URL request captured in a variable [In reply to] Can't Post

 
Oh I see now,

Yep, Lwp sure is what you need.

No Problem. Smile

perlkid

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives