From your program:
if ( $q->param() ) { #if params are not undef # ignore deleted next if ( $q->param("box$post_number") );
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.

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 &#039; 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.