Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting value from URL

Status
Not open for further replies.

JimJx

Technical User
Joined
Feb 16, 2001
Messages
202
Location
US
Hi all,

I am working with a script that needs to pull info from a URL similar to:


I have seen a couple threads that were similar to this, but unfortunately they only confused me further.

I know the first thing I need to do is get the name/value pairs, but I have no idea how to do this with perl.

If anyone has a script handy, or if you know where I can find a good example online for something like this, it would be greatly appreciated.

Jim
 
Code:
#!/usr/bin/perl

$temp=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$temp);
foreach $item(@pairs) {
        ($key,$content)=split (/=/,$item,2);
        $content=~tr/+/ /;
        $content=~ s/%(..)/pack("c",hex($1))/ge;
        $fields{$key}=$content;
}

$value1 = $fields{'value1'};
$value2 = $fields{'value2'};
...
$value1 will contain 12345
$value2 will contain abcde

Hope this helps!

Tim --
Tim <tim@planetedge.co.uk>
 


#!/usr/bin/perl

use CGI;

my $cgi = new CGI;
my $par_day = $cgi->param('p_day');
my $par_rep = $cgi->param('p_type');

If you have installed the CGI module, it will be more simple to use the param function.
 
but don't forget that 'QUERY_STRING' means that your form must be method=get
regards
peter
 
Yes, I agreed with Hongkongian. By the way CGI.pm is a standard module that come with the distribution of Perl ver. 5 and above if I'm not mistaken. So I don't think you might face any difficulties.

To get more info abt CGI.pm here the direction.

 
Gently, I suggest that this would be more appropriately pursued in the CGI forum where there is a FAQ on such matters.

;-)


keep the rudder amid ship and beware the odd typo
 
I disagree with goBoating. It's still a perl question. I'd guess that at least half of the post here are as much CGI-related as they are perl. I don't subscribe to the CGI forum because what I'm interested in are the perl-related questions, whether they are also CGI-related or not is irrelevant. I would assume that posts to the CGI forum had to do with the CGI INTERFACE spec, not the language used.

Maybe the FAQ mentioned should be posted to this forum as well?
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top