Well seeing that it is XMAS and all, this should get you going:

#!/usr/bin/perl -w use strict; my $script = "http://localhost/cgi-bin/test.pl"; my $file = "/tmp/data.txt"; use CGI; my $q = new CGI; print $q->header(); if ( $q->param('delete') ) { my @deletions = modify_file(); show_done_page(@deletions); show_form(); } else { show_form(); } exit; #### SUBS #### sub show_form { my @lines = get_file($file); # remove newlines; chomp (@lines); my @data = map { [ split ':', $_ ] } @lines; my $html = join "\n", map {qq!<p><input type="checkbox" name="dele +te" value="$_->[0]">$_->[0]:$_->[1]! } @data; print <<HTML; <form name="del" method="POST" action="$script"> $html <input type="Submit" name="Submit" value="Delete"> HTML } sub get_file { my $file = shift; open FILE, $file or die_nice("Could not open $file, Perl says $!") +; my @lines = <FILE>; close FILE; return @lines; } sub write_file { my $file = shift; open FILE, ">$file" or die_nice("Could not write $file, Perl says +$!"); print FILE @_; close FILE; } sub modify_file { my @deletions = $q->param('delete'); my $re = join '|', map { quotemeta } @deletions; $re = qr/^($re):/; my @lines = get_file($file); my @ok_lines = grep { not /$re/ } @lines; write_file($file, @ok_lines); return @deletions; } sub show_done_page { my @deletions = @_; my $html = join "\n", map { "$_<br>" } @deletions; print "<p>Deleted these entries:\n<p>$html"; } sub die_nice { my $error = shift; print "Sorry an error occurred: $error"; exit; }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print


In reply to Re: Text file updation by tachyon
in thread Text file updation by Anonymous Monk

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.