in reply to Parse template into data structure
use Template; { package MyStash; use base qw(Template::Stash); sub undefined { my $self = shift; my @ident = shift; print "(".join("|",@ident).")\n"; if (@ident > 1) { 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 $stash = MyStash->new; my $string = "The [% adjective %] [% noun %] [% verb %] over the river +.\n"; Template->new(STASH => $stash)->process(\$string);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parse template into data structure
by Rhandom (Curate) on Nov 07, 2006 at 16:02 UTC | |
by Anonymous Monk on Nov 07, 2006 at 19:14 UTC |