- 论坛徽章:
- 0
|
我也遇到过类似问题,下面一段代码供你参考:
open (my $fh, "+<$area_status_file")
or die "Can't open $area_status_file due to !\n";
$area = undef;
# synchronized access to the area file for multiple processes
my @areas;
while(<$fh>) {
chomp;
push @areas, $_;
}
for(my $i = 0; $i < scalar(@areas); $i ++ ) {
($break, $area, $new_line) = $coderef->($areas[$i]);
do {
$areas[$i] = $new_line;
last;
} if $break;
}
#reposition the pointer to start of file after copying
seek($fh, 0, SEEK_SET);
foreach my $line (@areas) {
print $fh "$line\n";
}
close $fh;
|
|
|