diff options
| author | fukachan <fukachan> | 2001-03-11 12:02:35 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2001-03-11 12:02:35 +0000 |
| commit | ebfe131226689bf1ab87f7d09dae111104ac2eb3 (patch) | |
| tree | bf8f1c7d989cdcb53b943f5d319b9b1e6be52760 /fml/lib/IO/Adapter/File.pm | |
| parent | c8785198f4d27a3f83ba1c5c2cbcdcfe9c4e33bc (diff) | |
| download | fml8-ebfe131226689bf1ab87f7d09dae111104ac2eb3.tar.gz fml8-ebfe131226689bf1ab87f7d09dae111104ac2eb3.tar.bz2 fml8-ebfe131226689bf1ab87f7d09dae111104ac2eb3.zip | |
replace() method and the checker
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> |
