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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |