retreive query string

Reply

Join Date: Jan 2009
Posts: 8
Reputation: perl1user is an unknown quantity at this point 
Solved Threads: 0
perl1user perl1user is offline Offline
Newbie Poster

retreive query string

 
0
  #1
Jan 10th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: retreive query string

 
0
  #2
Jan 10th, 2009
  1. use CGI;
  2.  
  3. chomp($name = param("name")); # // $name should have "foo" in it.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: retreive query string

 
0
  #3
Jan 11th, 2009
Originally Posted by perl1user View Post
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
Already answered on one or two other forums.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1
Reputation: summer_cherry is an unknown quantity at this point 
Solved Threads: 0
summer_cherry summer_cherry is offline Offline
Newbie Poster

Re: retreive query string

 
0
  #4
Jan 11th, 2009
  1. $str="http://server.com?name=foo&age=20&id=3&pass=123456";
  2. $str=~s/^.*?\?//;
  3. while($str=~m/(.*?)\b=(.*?)(&|$)/){
  4. print "$1----$2\n";
  5. $str=$';
  6. }
  7.  
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 763
Reputation: Phaelax is on a distinguished road 
Solved Threads: 38
Phaelax Phaelax is offline Offline
Master Poster

Re: retreive query string

 
0
  #5
Jan 15th, 2009
nevermind this post. The thread didn't show me there were any replies on the page before I responded.
Last edited by Phaelax; Jan 15th, 2009 at 8:03 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: retreive query string

 
0
  #6
Jan 15th, 2009
Originally Posted by summer_cherry View Post
  1. $str="http://server.com?name=foo&age=20&id=3&pass=123456";
  2. $str=~s/^.*?\?//;
  3. while($str=~m/(.*?)\b=(.*?)(&|$)/){
  4. print "$1----$2\n";
  5. $str=$';
  6. }
  7.  
how will that parse the query string? That parses a string. There is no need to do something like that anyway nor is it advisable, use the CGI module or a CGI sub class to parse query or form data.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 57
Reputation: mitchems is an unknown quantity at this point 
Solved Threads: 2
mitchems's Avatar
mitchems mitchems is offline Offline
Junior Poster in Training

Re: retreive query string

 
0
  #7
Feb 5th, 2009
  1. $qs=$ENV(QUERY_STRING);
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 57
Reputation: mitchems is an unknown quantity at this point 
Solved Threads: 2
mitchems's Avatar
mitchems mitchems is offline Offline
Junior Poster in Training

Re: retreive query string

 
0
  #8
Feb 5th, 2009
oops... I meant:

  1. $qs=$ENV{QUERY_STRING};

Since it is a hash.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 57
Reputation: mitchems is an unknown quantity at this point 
Solved Threads: 2
mitchems's Avatar
mitchems mitchems is offline Offline
Junior Poster in Training

Re: retreive query string

 
0
  #9
Feb 5th, 2009
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):

  1. ############
  2. sub getcgi {
  3. ############
  4. read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
  5. @pairs = split(/&/, $input);
  6. foreach $pair(@pairs) {
  7.  
  8. ($name, $value) = split(/=/, $pair);
  9. $name =~ tr/+/ /;
  10. $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  11. $value =~ tr/+/ /;
  12.  
  13. $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  14. #$value =~ s/< *(\/*)[^>]*script[^>]*>/<\1scrypt>/ig;
  15. #$value =~ s/< *(\/*)[^>]*iframe([^>]*)>/\*\1yframe\2\*/ig;
  16. $value=~tr/\'/\`/;
  17. $input{$name} = $value;
  18. }
  19. @vars = split(/&/, $ENV{QUERY_STRING});
  20. foreach $var(@vars) {
  21. ($v,$i) = split(/=/, $var);
  22. $v =~ tr/+/ /;
  23. $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  24. $i =~ tr/+/ /;
  25. $i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  26. $i =~ s/<!--(.|\n)*-->//g;
  27. $v =~ tr/\'/\`/;
  28. $info{$v} = $i;
  29. }
  30.  
  31. @vars = split(/;\s?/, $ENV{HTTP_COOKIE});
  32. foreach $var(@vars) {
  33. ($v,$i) = split(/=/, $var);
  34. $v =~ tr/+/ /;
  35. $v =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  36. $i =~ tr/+/ /;
  37. $i =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  38. $i =~ s/<!--(.|\n)*-->//g;
  39. $v =~ tr/\'/\`/;
  40. $cookie{$v} = $i;
  41. }
  42. }
  43.  
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC