Shortform: I need to take submitted data (consisting of multiple cases of { In=n Pn=decimalprice Qn=quantity ITn=price*quant } , perhaps discounted by js in the original page; validate it, and spit it back out to a new page in the original order, omitting the rows where Qn=(0 || undef).

At your own risk (or kindness), please read on...

Given:
  1. <apologetically> an ignorance, on my part, of db approaches... <apologetically>
  2. an ecommerce webpage where a typical row looks like this:
    <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>
  3. a hash, created (using a homebrew script which uses cgi.pm) by posting from a webpage orderform.
    The hash looks like this:
    %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

foreach(sort keys %form) { print "$_ $form{$_} \n"; }
which gives me
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:
\t "I[" . 0 . "]" .... "I[" . 570 ."]"
and <begin bewilderment> then get the whole mish-mash to look like:
%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!


In reply to sorting mixed alpha_digit keys of a hash? by ww

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.