http://qs321.pair.com?node_id=619707

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a small html form that has numbered params, 1..X and not always in order and the numbers will sometimes change and start at a higher number.

How can I get all the params into an array so I can loop over them and update a database with?

  • Comment on how to pull in all params that are numbered

Replies are listed 'Best First'.
Re: how to pull in all params that are numbered
by imp (Priest) on Jun 07, 2007 at 01:29 UTC
    use CGI; my $cgi = CGI->new; # using a list of parameters for my $key ($cgi->param()) { printf "%s=%s\n", $key, $cgi->param($key); } # Using a hash of key => value my %params = $cgi->Vars(); while (my ($key, $value) = each %params) { printf "%s=%s\n", $key, $value; }
Re: how to pull in all params that are numbered
by sulfericacid (Deacon) on Jun 07, 2007 at 01:00 UTC
    Not the best method but the quickest I thought of. Just send a hidden field with a list of comma separated values to your form. Ie: input type="hidden" name="numbers" value="1,2,3,6,8,9"); Since you're popping out the forum dynamically since you stated sometimes the numbers will change, just pop a list while printing the form.

    Update

    while(param()) { push (@num, $_) if $_ ~= m/^d$+/ } might work



    "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

    sulfericacid
      You should iterate the parameter list with for, not with while - while will result in an infinite loop.
        Actually it didn't result in an infinite loop and I asked in the chatterbox prior to posting and two other people said that param() should stop the loop once it's iterated through with for(). I could be wrong but when I tested it, it worked and stopped once the page loaded.


        "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

        sulfericacid