I've got an url of the form
www.server.com?data=a+b+c&other_data=f
and I'm just trying to extract the 'data' values, not the rest. I tried extracting from?data= to the first & it finds like this:
$bits =~ s/(q\=)(.+)(&)/$2/ but it doesn't work .. is the ampersand a special character? what am I missing? :(
thanks in advance!
$url = 'www.server.com?data=a+b+c&other_data=f';
($dom,$query_string) = split (/\?/,$url);
foreach $pair (split(/&/, $query_string)) {
($_n, $_v) = split(/=/, $pair);
## A full unpack is not required, all you have to deal with are spaces probably
$_v =~ s/[\+\%20]/ /g;
$qs{$_n} = $_v;
}
## you now have everything stored in a hash, or associative array, named %qs
print "content-type: text/html\n\n";
print "From URL $dom <br>\n";
foreach $k (keys %qs) {
print "key: $k value: $qs{$k} <br>\n";
}
## This should print
#www.server.com <br>
#key: other_data value: f <br>
#key: data value: a b c <br>
## so if you just wanted 'data'
print "$qs{'data'} <br>\n";