i.e text file contains
when i=2 then the text file should containbit rs_1 ; bit rs_2 ; bit rs_3 ;
when i=4 the text file should containbit rs_1 ; bit rs_2 ;
I have the following code , where is the problem ?bit rs_1 ; bit rs_2 ; bit rs_3; bit rs_4;
I am unable to get the output, where is the mistake ?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 $f +ile: $!\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"; }; }
In reply to How the lines will get modified as per value of i by suvendra123
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |