Well, the below sub works great but it seems a bit repetitious, to me at least. So can someone take a look at and fix up my 2:30am sub? :) In case your wondering, this sub chops up the query string into a hash. It also puts data from select boxes with multiple values into an array inside the hash.
sub formatParse {
my $buffer = shift;
my (%temp, %count, @params);
foreach my $pair (split /[&;]/, $buffer) {
my ($name, $value) = split /=/, $pair;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9]{2})/pack("c", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9]{2})/pack("c", hex($1))/eg;
push(@params, [$name, $value]);
$count{$name}++;
}
foreach my $key (@params) {
$coun{$key->[0]} = 0 unless $coun{$key->[0]};
if ($count{$key->[0]} == 1) {
$temp{$key->[0]} = $key->[1];
} else {
$temp{$key->[0]}->[$coun{$key->[0]}] = $key->[1];
$coun{$key->[0]}++;
}
}
return %temp;
}
Thanks!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.