Greetings Esteemed Monks,

Please forgive me if this question has been asked before. I Googled and Super Searched no avail. When using CGI.pm, I am wondering if there is any way to get the params in the order that they were in the form from which they came.

I recently had to dump a large (50+ fields) form into a text file and an email as quickly as possible. I dumped them into a hash (as I often do):

my @params; foreach ( $q->param() ) { push @params, $_; push @params, $q->param($_); } my %param = @params;
and then put them into the two destinations:
foreach my $key ( keys %param ) { print FILE "$key\t$param{$key}\n"; $email_content .= "$key:\t$param{$key}\n"; }
This was a quick fix to meet an irrational deadline. It was code to be replaced later when we had more time to properly insert the data into the appropriate db tables. I was then informed that for the email, the information needed to be in the order it was in on the form, and so I spent quite a bit of time arranging them by typing each one out.

$email_content .= "email_address:\t$param{email_address}\n";
Could this have been done another way? I could see this coming up again in a few months.

bassplayer


In reply to CGI Parameters in order by bassplayer

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.