many thanks for inspiration ;)
sub get_cgi_params_parse ($;$){
my ($str, $params) = @_;
my $res = {};
$str =~ tr/+/ /;
foreach (split /&/, $str){
my ($one, $two) = split /=/, $_;
$one =~ s/%([\da-fA-F][\dA-Fa-f])/pack("C", hex($1))/eg;
$two =~ s/%([\da-fA-F][\dA-Fa-f])/pack("C", hex($1))/eg;
if (exists $res->{$one}){
$res->{$one} .= "\n".$two;
}else{
$res->{$one} = $two;
}
$params->{$one} = $res->{$one};
}
return $res;
}
sub get_cgi_params (;$$$$){
my ($get_str, $post_str, $cookie_str, $force_get) = @_;
my $res = {_names => [], get => {}, post => {}, cookies => {}, vars
+=> {}};
$force_get = 0 unless defined $force_get;
$cookie_str = $ENV{'HTTP_COOKIE'} unless defined $cookie_str;
if ($cookie_str){
foreach (split /; /, $cookie_str){
m/^(.+?)(=(.*))?$/;
$res->{cookies}->{$1} = $3;
}
}
if ($force_get or $ENV{'REQUEST_METHOD'} eq "GET" ){
$get_str = $ENV{'QUERY_STRING'} unless defined $get_str;
$res->{get} = get_cgi_params_parse $get_str, $res->{vars} if $ge
+t_str;
}
if ($ENV{'REQUEST_METHOD'} eq "POST"){
read(STDIN, $post_str, $ENV{'CONTENT_LENGTH'}) unless defined $pos
+t_str;
$res->{post} = get_cgi_params_parse $post_str, $res->{vars} if $po
+st_str;
}
return $res;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.