Here is my proposal which has a somewhat simpler logic utilizing the empty string to print nothing:
use strict; use warnings; my $previous=""; while(<DATA>){ if(/XXXXX/){ <DATA>; $previous=""; }else{ print $previous; $previous=$_; } } print $previous; __DATA__ PPPPP XXXXX is my name YYYYY KKKKK UUUUU BBBBB CCCCCC XXXXX is what I play KKKKK NNNNN
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to check for a word in a file and if found remove that line, the above line and the below line from the file.
by ikegami (Patriarch) on Jan 22, 2016 at 16:27 UTC | |
by hdb (Monsignor) on Jan 22, 2016 at 19:16 UTC |