| | |
retreive query string
![]() |
•
•
Join Date: Jan 2009
Posts: 8
Reputation:
Solved Threads: 0
how do I retreive query string in perl ?
let's say I have http://server.com?name=foo
how do I get the value of 'name'
thx
cvv3@yahoo.com
let's say I have http://server.com?name=foo
how do I get the value of 'name'
thx
cvv3@yahoo.com
perl Syntax (Toggle Plain Text)
use CGI; chomp($name = param("name")); # // $name should have "foo" in it.
•
•
•
•
how do I retreive query string in perl ?
let's say I have http://server.com?name=foo
how do I get the value of 'name'
thx
cvv3@yahoo.com
•
•
Join Date: Jan 2009
Posts: 1
Reputation:
Solved Threads: 0
Perl Syntax (Toggle Plain Text)
$str="http://server.com?name=foo&age=20&id=3&pass=123456"; $str=~s/^.*?\?//; while($str=~m/(.*?)\b=(.*?)(&|$)/){ print "$1----$2\n"; $str=$'; }
•
•
•
•
Perl Syntax (Toggle Plain Text)
$str="http://server.com?name=foo&age=20&id=3&pass=123456"; $str=~s/^.*?\?//; while($str=~m/(.*?)\b=(.*?)(&|$)/){ print "$1----$2\n"; $str=$'; }
I would suggest using the CGI module as well, but if you really want to do it by hand... Here is an extremely messy, but effective way of parsing (not strict BTW):
Perl Syntax (Toggle Plain Text)
############ sub getcgi { ############ read(STDIN, $input, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $input); 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 =~ s/< *(\/*)[^>]*script[^>]*>/<\1scrypt>/ig; #$value =~ s/< *(\/*)[^>]*iframe([^>]*)>/\*\1yframe\2\*/ig; $value=~tr/\'/\`/; $input{$name} = $value; } @vars = split(/&/, $ENV{QUERY_STRING}); foreach $var(@vars) { ($v,$i) = split(/=/, $var); $v =~ tr/+/ /; $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $i =~ tr/+/ /; $i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $i =~ s/<!--(.|\n)*-->//g; $v =~ tr/\'/\`/; $info{$v} = $i; } @vars = split(/;\s?/, $ENV{HTTP_COOKIE}); foreach $var(@vars) { ($v,$i) = split(/=/, $var); $v =~ tr/+/ /; $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $i =~ tr/+/ /; $i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $i =~ s/<!--(.|\n)*-->//g; $v =~ tr/\'/\`/; $cookie{$v} = $i; } }
![]() |
Similar Threads
- GridView in ASPX (C#)
- where to put .asp code into html code (ASP.NET)
Other Threads in the Perl Forum
- Previous Thread: running perl
- Next Thread: perl project command line arg?
| Thread Tools | Search this Thread |






