From ebfe131226689bf1ab87f7d09dae111104ac2eb3 Mon Sep 17 00:00:00 2001 From: fukachan Date: Sun, 11 Mar 2001 12:02:35 +0000 Subject: replace() method and the checker --- fml/lib/IO/Adapter/File.pm | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'fml/lib/IO/Adapter/File.pm') diff --git a/fml/lib/IO/Adapter/File.pm b/fml/lib/IO/Adapter/File.pm index 26bd628a..112404bb 100644 --- a/fml/lib/IO/Adapter/File.pm +++ b/fml/lib/IO/Adapter/File.pm @@ -254,6 +254,7 @@ sub add my $wh = $self->{ _wh }; if (defined $fh) { + FILE_IO: while (<$fh>) { print $wh $_; } @@ -300,6 +301,41 @@ sub delete } +=head2 C + +replace lines which matches $regexp with $value. + +=cut + +sub replace +{ + my ($self, $regexp, $value) = @_; + + $self->open("w"); + + my $fh = $self->{ _fh }; + my $wh = $self->{ _wh }; + + if (defined $fh) { + FILE_IO: + while (<$fh>) { + if (/$regexp/) { + print $wh $value, "\n"; + } + else { + print $wh $_; + } + } + close($fh); + $wh->close; + } + else { + $self->_error_reason("Error: cannot open file=$self->{ _file }"); + return undef; + } +} + + =head1 SEE ALSO L -- cgit v1.2.1