Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: 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 mr_ron (Chaplain)
on Jan 21, 2016 at 11:01 UTC ( #1153266=note: print w/replies, xml ) Need Help??


in reply to 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.
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 are going to read the whole file into memory you also allow for the following solution which seems more simple and direct than working with splice.

use strict; use warnings; my $file_content = do { local $/ = undef; <DATA>; }; $file_content =~ s/ (?:.*\n)? ^X{5}.*\n (?:.*\n)?//xmg; print $file_content; __DATA__ XXXXX Aoooo XXXXX is my name Boooo 11111 22222 33333 Coooo XXXXX is what I play Doooo 44444
Ron
  • Comment on Re^3: 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.
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1153266]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2022-12-09 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?