>>>>> "JWK" == John W Krahn <jwkr...@shaw.ca> writes:
JWK> There are a few ways to do what you require: and you missed the simplest one so far (i did mention edit_file): JWK> #!/usr/bin/perl JWK> use strict; JWK> use warnings; use File::Slurp qw( edit_file ) ; edit_file { s/Dood/Dude/g } $file ; and if you need a counter: my $change_cnt ; edit_file { $change_cnt = s/Dood/Dude/g } $file ; $change_cnt ||= 0 ; print "made my $change_cnt ; JWK> tie my @buffer, 'Tie::File', 'data.txt' or die "Cant open data.txt $!"; JWK> for ( @buffer ) { JWK> s/Dood/Dude/ and last; JWK> } JWK> __END__ JWK> #!/usr/bin/perl JWK> use strict; JWK> use warnings; JWK> local ( $^I, @ARGV ) = ( '', 'data.txt' ); JWK> while ( <> ) { JWK> ?Dood? && s/Dood/Dude/; JWK> print; JWK> } JWK> __END__ JWK> #!/usr/bin/perl JWK> use strict; JWK> use warnings; JWK> use Fcntl ':seek'; JWK> open my $FP, '+<', 'data.txt' or die "Cant open data.txt $!"; JWK> read $FP, my $buffer, -s $FP or die "Cant read from data.txt $!"; JWK> seek $FP, 0, SEEK_SET or die "Cant seek on data.txt $!"; JWK> $buffer =~ s/Dood/Dude/; JWK> print $FP $buffer; JWK> __END__ JWK> John JWK> -- JWK> Any intelligent fool can make things bigger and JWK> more complex... It takes a touch of genius - JWK> and a lot of courage to move in the opposite JWK> direction. -- Albert Einstein JWK> -- JWK> To unsubscribe, e-mail: beginners-unsubscr...@perl.org JWK> For additional commands, e-mail: beginners-h...@perl.org JWK> http://learn.perl.org/ -- Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com -- ------------ Perl Developer Recruiting and Placement Services ------------- ----- Perl Code Review, Architecture, Development, Training, Support ------- -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/