I use Mason for my websites, so I don't usually run into the issue of getting variables. However, I need to dynamically get my variables (so I don't have to initialize each one).
<form method="get" action="test_list.html"> <input type="hidden" name="LineItem" value="1" /> First Number: <input type="text" name="first-1" /><br /> Second: <input type="text" name="second-1" /><br /> Third: <input type="text" name="third-1" /> </p> <p> <input type="hidden" name="LineItem" value="2" /> First Number: <input type="text" name="first-2" /><br /> Second: <input type="text" name="second-2" /><br /> Third: <input type="text" name="third-2" /> </p> <input type="submit" name="a" value="go"> </form>
From a form like that I need to keep the components together that end in the same number so I can do something with it from the database. I found a mailing list post that suggested the following, but I kept getting an error from it:
foreach (values $ARGS{LineItem}) { $SQL->execute( $PONum, $ARGS{"first-${i}"}, $ARGS{"second-${i}"}, $ARGS{"third-${i}"} ); }
I tried a few things but my main problem was getting the LineItem variable into an array (not an array of arrays). So it only gets one of the sets of variables.
my @lineitems = $ARGS{"LineItem"}; foreach my $line (@lineitems) { print "line is @$line[0]"; print $ARGS{"first-@$line[0]"}; print $ARGS{"second-@$line[0]"}; print $ARGS{"third-@$line[0]"}; }
I am guessing I am getting CLOSE, but I can't quite complete it without some help. Thanks!


Michael Jensen
inblosam.com

In reply to Parsing cgi variable lists by inblosam

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.