I am beginning to think I am going about this all wrong. My news script makes me happy. Any client can use the form to update their pages. The script writes new table rows to a txt file (used later as an SSI)and delimits each entry with 3 newlines. Currently clients edit via a script which makes a form with a text area containing the whole contents of the text file, HTML and all. They complain that it is hard to see which post they want to delete or edit due to the HTML. So I have, with help from Physi and others, made the script below whose output looks like this.

Problem is that I can't figure how to identify the post to be deleted via the checkboxes. Should I be thinking line numbers and use seek to excise the selected bits? I tried making the checked value of each button eq $_ (whose value creates the contents of the nested table next to the checkbox, but that made the script go crazy.

Advice on high level logic most welcome, I'm not asking for a code handout, but maybe a map on a cocktail napkin?
TIA
jg

#!/usr/bin/perl -w use strict; use CGI; use CGI ':standard'; use CGI::Carp qw/fatalsToBrowser /; my $q = CGI->new(); my $path_to_text="/home/nolaflash/www/exp/news/body.txt"; my $post_number; print header; #only just beginning to work out using standard print "<HTML><BODY><center>"; print "<form method=post action=http://www.nolaflash.com/cgi-bin/editi +ngscript.pl>\n"; print "<TABLE width=600>"; print "<TR bgcolor=#000066><TD colspan=2 align=center><font color=#ff +ffff>"; print "<h2>Edit Your Posts</h2></font></TD>"; open (FH, "$path_to_text") or die "where's the damn file? : $!"; $/="\n\n"; #set the input Record seperator to + a double newline while (<FH>) { next if /^\n+$/; #ignore lines which contains only +newlines $post_number++; print "<TR><TD valign=top>Delete This Post?<input type=checkbox name +=box$post_number value=onepost> </TD>\n"; print "<TD><table width=295><TR><TD>$_\n"; #print the textblock in +a nested table with an ... print "</TD></TR></TABLE></TD></TR>\n"; print "<TR bgcolor=#000066><TD colspan=2>&nbsp;</TD>"; #appending +darkline print "</TR>\n"; } close FH; print "<TR bgcolor=#333333><TD align=center colspan=2><input type=subm +it name=Submit value=\"Delete Checked Posts\"></TD>"; print "</form></center></table></body></html>"; exit;
_____________________________________________________
If it gets a little bit out of hand sometimes, don't let it fool you into thinkin' you don't care.TvZ

In reply to Working on Deleting Sections of Text File Delimited by Newlines 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.