diff options
Diffstat (limited to 'fml/lib/IO/Adapter/File.pm')
| -rw-r--r-- | fml/lib/IO/Adapter/File.pm | 36 |
1 files changed, 36 insertions, 0 deletions
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($regexp, $value)> + +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<IO::MapAdapter> |
