poir,
As others have pointed out, you probably need
to do some type of "buffering." There is a slightly
novel recipe (14.7) in the cookbook that outlines an
alternative most askers of this question would probably like.
to paraphrase 14.7
#!/usr/bin/perl
use DB_File;
my $file = shift;
print "usage $0 filename" unless $file;
tie( @array, "DB_File", $file, O_RDWR, 0666, $DB_RECNO )
|| die "Cannot open file $file ($!)\n";
if( $array[1] =~ /word4/ ) {
$array[0] = "this line now changed";
}
untie @array;
A good way to waste ... er learn some perl would be
to benchmark this approach against one of the other buffering approaches.
-derby