Search code examples
perlperl-module

Perl generate a file based on a template


I am working on a use case that requires me to generate .hpp files based on a template. So something like

#ifdef changethis_hpp
#define changethis_hpp

#include<fixedheader1>
...
#include<fixedheaderN>

class changethis
{
....
};

needs to be generated based on the requirement of changethis string. How can I achieve this in perl?

WHITSF I wrote a fixed template.txt file and and then replaced the text with changethis string and then dumped it as a changethis.hpp.

But is there any other way I can achieve this in perl?


Solution

  • I use Text::Template for such tasks.