diff options
| -rw-r--r-- | fml/lib/IO/Adapter/File.pm | 12 | ||||
| -rwxr-xr-x | fml/lib/IO/t/delete.pl | 15 |
2 files changed, 14 insertions, 13 deletions
diff --git a/fml/lib/IO/Adapter/File.pm b/fml/lib/IO/Adapter/File.pm index 1e364073..33c33f91 100644 --- a/fml/lib/IO/Adapter/File.pm +++ b/fml/lib/IO/Adapter/File.pm @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: File.pm,v 1.36 2002/07/25 11:34:02 fukachan Exp $ +# $FML: File.pm,v 1.37 2002/08/19 15:06:35 fukachan Exp $ # package IO::Adapter::File; @@ -377,20 +377,20 @@ sub add } -=head2 C<delete($regexp)> +=head2 C<delete($key)> -delete lines which matches $regexp from this map. +delete lines with key $key from this map. =cut # Descriptions: delete address(es) matching $reexp from map -# Arguments: OBJ($self) STR($regexp) +# Arguments: OBJ($self) STR($key) # Side Effects: update map # Return Value: same as close() sub delete { - my ($self, $regexp) = @_; + my ($self, $key) = @_; $self->open("w"); @@ -400,7 +400,7 @@ sub delete if (defined $fh) { FILE_IO: while (<$fh>) { - next FILE_IO if /$regexp/; + next FILE_IO if /^$key\s+\S+|^$key\s*$/; print $wh $_; } $fh->close; diff --git a/fml/lib/IO/t/delete.pl b/fml/lib/IO/t/delete.pl index 7fb96ba8..b20bc4f4 100755 --- a/fml/lib/IO/t/delete.pl +++ b/fml/lib/IO/t/delete.pl @@ -4,7 +4,7 @@ # All rights reserved. This program is free software; you can # redistribute it and/or modify it under the same terms as Perl itself. # -# $FML: delete.pl,v 1.4 2001/08/19 16:12:25 fukachan Exp $ +# $FML: delete.pl,v 1.5 2002/04/01 23:41:14 fukachan Exp $ # use strict; @@ -14,14 +14,17 @@ my $org_file = "/etc/passwd"; my $file = "/tmp/passwd"; my $tmpf = "/tmp/passwd.tmp"; my $map = "file:". $file; -my $buffer = '^root'; +my $buffer = 'root'; ### MAIN ### print "${map}->delete() "; # prepare -system "head -1 $org_file > $tmpf"; -system "cp $org_file /tmp/"; +system "head -1 $org_file | tr ':' ' ' > $tmpf"; +system "cat $org_file | tr ':' ' ' > $file"; + +# orignal +my $orgbuf = GetContent($file); # append use IO::Adapter; @@ -31,15 +34,13 @@ if ($obj->error) { croak( $obj->error );} # verify the result # assemble the original from the deleted line and modified file itself. -my $orgbuf = GetContent($org_file); my $buf = GetContent($tmpf) . GetContent($file); if ($buf eq $orgbuf) { print " ... ok\n"; } else { - print " ... fail\n"; - system "diff -ub $org_file $file"; + print " ... fail <$buf> ne <$orgbuf>\n"; } |
