in reply to Problem changing only first occurence of pattern in file

Please give your questions meaningful titles.

You're probably better off using Tie::File for something like this.

use Tie::File; tie my @file, 'Tie::File', 'user.txt'; for (@file) { s/\|No$/|Yes/ and last; }
--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Problem changing only first occurence of pattern in file
by jwkrahn (Abbot) on Oct 17, 2006 at 17:48 UTC
    Don't forget to make the back-up file and also verify that the file was opened correctly:   :-)
    use Tie::File; use File::Copy; my $file = 'user.txt'; copy $file, "$file.bak" or die "Cannot copy '$file' $!"; tie my @file, 'Tie::File', $file or die "Cannot open '$file' $!"; for ( @file ) { s/\|No$/|Yes/ and last; }