Here your code checks to see if there are any params, which is good, but the next line is an out-of-place next. You don't have any logic in place to loop through the individual params themselves. $q->params() contains only the names of all the checkboxes which were selected (checked) along with your submit button value and anything else in the form. When you are at this point in the script (after submit), you don't know which checkboxes are going to be in $q->params(), if any.if ( $q->param() ) { #if params are not undef # ignore deleted next if ( $q->param("box$post_number") );
Therefore you need to examine $q->params(), look at the checkbox values and associate them with the appropriate "post" text in your file. Here's a little bit of code that I hope will get you started:
# Pull out the numbers of the checkboxes that were selected. # e.g. If box1, box3 and box12 were selected, @selected = (1, 3, 12) my @selected = grep { $_=$1 if /^box(\d+)/; } $q->params(); open FH, $filename or die "Can't read $filename, $!"; # open for read my @posts = <FH>; # This should delete the post text associated with each selected check +box # You have to use the @selected array in reverse. I leave the # explanation for this as an exercise for you. :) splice @posts, ($_ - 1), 1 for reverse @selected; # Now write the file back out again open FH, ">$filename" or die "Can't write to $filename, $!"; print FH @posts or die "Couldn't write to file, $!"; close FH or die "Can't close file etc, $!";
BTW I think you need to use ' rather than ' when encoding single quotes. ' is an XML character entity.
In reply to Re: Re: Loading $_ as checkbox value when $_ has double quotes in its value
by virtualsue
in thread Loading $_ as checkbox value when $_ has double quotes in its value
by jerrygarciuh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |