[PLUG] Perl: deleting text

Jeme A Brelin jeme at brelin.net
Tue Feb 3 16:09:01 UTC 2004


On Tue, 3 Feb 2004, Brian Derr wrote:
> I'm fairly new to Perl and have been working on a small script.  Thus
> far I've got it working perfectly but have one question, how do I remove
> text from a file?  I am keeping a plain text file with records that are
> separated by a '\n\n'.  How would I go about deleting a record? I tried
> getting help on #perl in freenode but no one responded so I thought I'd
> take it to my favorite LUG.  :-)

Um, context is important here.  You're reading in a file then writing it
out again?  Then you delete it by not writing it.

What kind of records are these?  Have you considered using a SwissArmy
Chainsaw type tool like DBD::CSV (this allows you to treat a flat file
like a database and use SQL against it)?

Details, details.

oh, and `sed /pattern/d file` works pretty well, too.

J.
-- 
   -----------------
     Jeme A Brelin
    jeme at brelin.net
   -----------------
 [cc] counter-copyright
 http://www.openlaw.org




More information about the PLUG mailing list