Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

how to pull in all params that are numbered

by Anonymous Monk
on Jun 07, 2007 at 00:55 UTC ( #619707=perlquestion: print w/ replies, xml ) Need Help??
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
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
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; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://619707]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2014-08-31 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls