ww has asked for the wisdom of the Perl Monks concerning the following question:
At your own risk (or kindness), please read on...
<td scope="row">A. millefolium 'Summer Wine'<input type="hidden" name= +"I1" value="A. millefolium 'Summer Wine'"></td> <td><label for="Q1"><input type="text" id="Q1" name="Q1" size="3" onch +ange="calc_item(order,6);"></label></td> <td><label for="P1">1 gal <input type="text" id="P1" name="P1" value=" +3.95" onfocus="this.blur();" size="4"></label></td> <td><label for="IT1"><input type="text" id="IT1" name="IT1" value="0" +size="6" onfocus="this.blur();"></label></td>
%form = ( 'IT3' => '6.99', 'I0' => '0', 'I3' => '3', 'Q3' => '1', 'P0' => '3.95', 'IT0' => '129.05', 'P3' => '6.99', 'Q0' => '40', 'IT10' => '36.50', 'P10' => '3.65', 'I10' => '10', 'Q10' => '10' <... snip> );
While it's trivial to sort that alphabetically by
which gives meforeach(sort keys %form) { print "$_ $form{$_} \n"; }
I0 0 I10 10 I3 3 IT0 129.05 IT10 36.50 IT3 6.99 P0 3.95 P10 3.65 ...
But what I really seek is a way to get ALL the elements of the hash back into the same order in which they were submitted (ie, same order as in the intial webpage) -- because after unTainting, valdiating, removing items for which Qn and/or ITn are 0 and so on, the script uses them to populate a confirmation page ("Here's what I think you ordered; OK?)
One (perhaps "half-baked") notion is to extract the keys, split each between the alpha(s) and the digit(s)like:and <begin bewilderment> then get the whole mish-mash to look like:\t "I[" . 0 . "]" .... "I[" . 570 ."]"
%form = ( 'I0' => '0', 'Q0' => '40', 'P0' => '3.95', 'IT0' => '129.05', 'I3' => '3', 'Q3' => '1', 'P3' => '6.99', 'IT3' => '6.99', 'I10' => '10', 'Q10' => '10' 'P10' => '3.65', 'IT10' => '36.50', ... 'IT647' => 741.34 );
...because I don't really have any idea how to create the confirmation page's (600+ products omitting the quant=0 items) otherwise.
<++bewilderment> Truth be told, I'm not even sure whether this is a design question, an algorithm question or a reasonable question for the Monestary.
</bewilderment>
Nonetheless, I'm seeking pointers and advice. Thanks for reading!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sorting mixed alpha_digit keys of a hash?
by jdporter (Paladin) on Mar 22, 2006 at 19:04 UTC | |
|
Re: sorting mixed alpha_digit keys of a hash?
by japhy (Canon) on Mar 22, 2006 at 19:33 UTC | |
|
Re: sorting mixed alpha_digit keys of a hash?
by zer (Deacon) on Mar 22, 2006 at 19:09 UTC | |
by ww (Archbishop) on Mar 22, 2006 at 19:33 UTC |