Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Template Modules in Core

by Anonymous Monk
on May 12, 2011 at 16:18 UTC ( [id://904455]=perlquestion: print w/replies, xml ) Need Help??

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

What are my option to use Core Modules for templating, other than unpack or format? I am using 5.8.8 and I do not have TT2 in it. Thanks.

Replies are listed 'Best First'.
Re: Template Modules in Core
by educated_foo (Vicar) on May 12, 2011 at 17:06 UTC
    There's also s///e (as used in Template::Tiny):
    # load values into %config, template into $string, then... 1 while $string =~ s/\[%\s*(\S+)\s*%\]/$config{$1}/;
    or just plain old string interpolation:
    # load values into e.g. $CONFIG::variable1, etc., then... $string = eval "package CONFIG;\n<<END_TEMPLATE;\n".$string."\nEND_TEM +PLATE\n";
    Basically, if you just have to substitute in some variables, it's not worth using a fancy framework. If you have to do more, you won't find any module to help you in core Perl.
Re: Template Modules in Core
by Anonymous Monk on May 12, 2011 at 16:20 UTC
Re: Template Modules in Core
by sundialsvc4 (Abbot) on May 12, 2011 at 16:44 UTC

    There are no templating modules “in the core.”   You have to select them and install them yourself.   Google the topic of “using perl as a non-root user.”

Re: Template Modules in Core
by Khen1950fx (Canon) on May 12, 2011 at 17:05 UTC
    You can get TT2 here.
Re: Template Modules in Core
by anonymized user 468275 (Curate) on May 13, 2011 at 15:37 UTC
    I am used to having this kind of client environment, so I tend to use my own template processing, for example putting placeholders in a file, e.g. __ID__ and using bog-standard substitution. A useful standard tool in unix is the C preprocessor which, with a little Perl programming around it, can be used for fairly comprehensive templating of just about anything, in spite of it being designed for C language preprocessing. In fact a home-grown templating module based on the C-preprocessor could be worth doing if the requirement is a persistent one.

    One world, one people

      Big ups m4! (m4 is the C-preprocessor) Update: or is it...? D'oh! no it's not! It's a macro language that, I think, originally came with sendmail... I suck!

      http://www.gnu.org/software/m4/manual/m4.html

      I use m4 all the time for random stuff. I find it's best for jobs that require you to type the same or similar stuff over.. and over.. and over.. but not so good for stuff that requires calculating something. EG my nagios configs are really repetitive, so m4=good. Making a dynamic web page: m4=not-so-good. A good mix would be a perl script that generates an m4 file full of definitions which m4 places in the result files. Aaannd of course you'd have a Makefile to make that easy to use. Aaaand you'd use m4 to make the Makefile less of a hastle... Aaaand you'd use perl to make the m4 less dumb....

      Hmm...

      Yeah, usually around this point I realise I should have stayed away from m4...

      Did I mention that I suck...?

        m4 has indeed become more popular even on non-linux platforms. Although it isn't the cpp, it is certainly descended from it. It can be awkard with Perl templating because Perl has a much too flexible syntax. But for that reason Perl needs it the least. However, I can't see any problem using m4 or the cpp with say HTML templating - no conflict of syntax for example.

        One world, one people

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://904455]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-03-19 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found