in reply to Re: 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.
in thread 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.
If you spot the trick please explain it to... me!use strict; use warnings; my @unv; my $pos; while (<DATA>){push @unv,$.-1,$.,$.+1 if /XXXXX/;$pos=(tell DATA)-leng +th $_ unless $pos} seek DATA,$pos,0; while (<DATA>) {print unless $.-__LINE__ ~~ @unv} __DATA__ XXXXX Aoooo XXXXX is my name Boooo 11111 22222 33333 Coooo XXXXX is what I play Doooo 44444 # OUTPUT 11111 22222 33333 44444
use strict; use warnings; my @unv; my $pos; while (<DATA>){push @unv,$.-1,$.,$.+1 if /XXXXX/;$pos=(tell DATA)-leng +th $_ unless $pos} seek DATA,$pos,0; $.=0; while (<DATA>) {print unless $. ~~ @unv}
|
|---|