in reply to Re: Parse template into data structure
in thread Parse template into data structure
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Parse template into data structure
by Anonymous Monk on Nov 07, 2006 at 19:14 UTC |