Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Looping over all checked boxes w/

by Anonymous Monk
on Mar 21, 2002 at 19:21 UTC ( #153391=perlquestion: print w/replies, xml ) Need Help??

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?


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.


    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 }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://153391]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (1)
As of 2022-10-03 01:59 GMT
Find Nodes?
    Voting Booth?
    My preferred way to holiday/vacation is:

    Results (13 votes). Check out past polls.