rsiedl has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,

Can anyone suggest a module or method to replace text in an external file?
Heres some code to demonstrate what I mean.
File contains:
<!-- start editable area 1 --> this is some text <!-- end editable area 1 -->
The aim is for the script to read in the file, replace whats in between the comments with some other text, and then write the file to disk.
Oh, and there could be more than one editable area with a file...
Cheers.

Replies are listed 'Best First'.
Re: How to replace text in external file
by idle (Friar) on Feb 06, 2006 at 12:01 UTC

      And something like Tie::File to make the file reading / rewriting nice and simple.

Re: How to replace text in external file
by NiJo (Friar) on Feb 06, 2006 at 19:02 UTC
    You can roll your own templating system. But using an existing one (Text::Template ?) saves a lot of work.
      Hi,
      Thanks for your response. I'm already using HTML::Template and am trying to create a Content Management System :)