ArifS has asked for the wisdom of the Perl Monks concerning the following question:
Content of the test1.txtuse strict; use warnings; my $filename = 'test1.txt'; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; my $line; my $flag=1; while($line=<$fh>) { if($flag == 0) { print $line; next; } if($line=~/sample-text/) { $flag=0; print $line; } }
Expected outputText_1 sample-text file Text_1 matching the 1st line matching the last line Text text_1 text-2 sample-text file text-2 matching the 1st line matching the last line
But it only removes the 1st line, and doesn't look for other lines. Please let me know.sample-text file Text_1 matching the 1st line matching the last line text text_1 sample-text file text-2 matching the 1st line matching the last line
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: match a word and delete last line
by tybalt89 (Monsignor) on May 23, 2017 at 13:40 UTC | |
by ArifS (Beadle) on May 23, 2017 at 14:03 UTC | |
by tybalt89 (Monsignor) on May 23, 2017 at 14:17 UTC | |
by ArifS (Beadle) on May 23, 2017 at 14:23 UTC | |
by ArifS (Beadle) on May 23, 2017 at 13:45 UTC | |
|
Re: match a word and delete last line
by hippo (Archbishop) on May 23, 2017 at 13:49 UTC | |
|
Re: match a word and delete last line
by BillKSmith (Monsignor) on May 23, 2017 at 22:59 UTC |