Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Parse template into data structure

by Hofmator (Curate)
on Nov 07, 2006 at 09:33 UTC ( #582594=note: print w/replies, xml ) Need Help??

in reply to Parse template into data structure

I don't know much about Template::Toolkit and its innards, so I can't tell you if there is a (un)documented way to get at the information you want.

But a simple template basically comes down to some text ... [% variable_name %]... some more text. If this is the case with your templates you can easily parse them directly with something like the following:

local $/; my $text = <DATA>; while ($text =~ /\[%(.*?)%\]/g) { print "$1\n"; } __DATA__ some text ... [% variable_name %] ... some more text [% variable_name2 %] [% variable_name3 %] ... some more text some text ... [% variable_name4 %]

-- Hofmator

Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2016-10-25 06:08 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (315 votes). Check out past polls.