bit rs_1 ;
bit rs_2 ;
bit rs_3 ;
####
bit rs_1 ;
bit rs_2 ;
####
bit rs_1 ;
bit rs_2 ;
bit rs_3;
bit rs_4;
####
my $file = 'abc.txt';
{
open my $in_fh, '<', $file or die "Cannot open input file: $!\n";
flock $in_fh, LOCK_EX | LOCK_NB or die "Cannot obtain a lock on $file: $!\n";
my $temp_out = File::Temp->new(TEMPLATE => "$0-$$-XXXXX");
while (my $line = <$in_fh>) {
while ( $line =~ /-abc\s(\d+)/g ) {
my $first = $1;
if (my ($tail) = $line =~ /^\.march_endSP)(.*)/) {
print(".rs_$_$tail\n") for 1..$first;
} else {
print($line);
}
}
close $in_fh or die "Failed to close $in_fh. Aborting. $!\n";
$temp_out->flush;
eval {
move($temp_out->filename, $in_fh);
} or do {
warn "Failed to swap $temp_out into $in_fh: $!\n";
};
}