http://qs1969.pair.com?node_id=153391

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

Hi All,

I have a very simple question that has bugged me on more than one occasion - i am printing a list of checkboxes, now what I want to do is scan all the check boxes and remove and files that are checked

I have tried a:
while ( $query->param() ) { # .. snip.. (delete if checked) }
but this starts an everlasting loop and the program just hangs..any thoughts?

Thanks

Title edit by tye

Replies are listed 'Best First'.
(Ovid) Re: Very Simply
by Ovid (Cardinal) on Mar 21, 2002 at 19:24 UTC

    while will execute while a condition evaluates as true. What you want to do is iterate over your params. foreach is one way to do this:

    foreach ( $query->param ) { # do stuff }

    However, I would look down on this in a code review (probably) as one typically needs to treat each parameter as a special case and untaint it according to your needs. Iterating over all of the parameters suggests that this is not being done.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Re: Very Simply
by earthboundmisfit (Chaplain) on Mar 21, 2002 at 19:43 UTC
    There are a lot of ways to do it. You only want the check boxes, so what I would do is first check to make sure all my checkboxes have the same name and then store them in an array like this:
    #! Perl -w use strict; use CGI; my $q = new CGI; my @checkbxs = $q->param('the_name'); # only those that are checked en +d up in here for (@checkbxs) { &delete_file($_); # assuming a delete sub exists }