in reply to Re: Parse template into data structure
in thread Parse template into data structure

And if you'd rather use CGI::Ex::Template (which is Template::Toolkit compatible template wise) you could use the following code (I'd use CGI::Ex::Template personally - but that might be because I'm intimately familiar with it :)).

use CGI::Ex::Template; my $cet = CGI::Ex::Template->new( UNDEFINED_GET => sub { my $self = shift; my $ident = shift; print "(".join("|",@$ident).")\n"; if (@$ident > 2) { return ''; } elsif ($ident->[0] eq 'adjective') { return 'red'; } elsif ($ident->[0] eq 'noun') { return 'fox'; } elsif ($ident->[0] eq 'verb') { return 'jumped'; } else { return ''; } }, ); my $string = "The [% adjective %] [% noun %] [% verb %] over the river +.\n"; $cet->process(\$string);


my @a=qw(random brilliant braindead); print $a[rand(@a)];

Replies are listed 'Best First'.
Re^3: Parse template into data structure
by Anonymous Monk on Nov 07, 2006 at 19:14 UTC
    UNDEFINED_GET in this package appears to be able to do what I had in mind. I will have to take some time to play with it a bit. Thank you.