#!/usr/bin/perl use strict; use warnings FATAL => 'all'; use Data::Dumper; use Term::ReadLine; use HTML::Template::Expr; my %data = ( a => 5, b => 1, c => 7, d => 100, ); my $term = Term::ReadLine->new('foo'); my $expr; while (1) { $expr = $term->readline('Enter expression: '); my $tmpl = compile($expr,[keys %data]); $tmpl->param(\%data); print Dumper ($tmpl->output); } sub compile { my $expr = shift; my $known_cols = shift; my $tmpl_expr = ""; $tmpl_expr .= sprintf ('<TMPL_VAR expr="%s">', $expr); # # 'declare' known 'columns' # $tmpl_expr .= join('', map {sprintf('<TMPL_IF "%s"></TMPL_IF>',$_)} +@$known_cols); warn("expr=$tmpl_expr"); return HTML::Template::Expr->new( die_on_bad_params => 1, scalarref => \$tmpl_expr); }
In reply to Re: Parse user-entered expressions into subs for an awk-like program
by snoopy
in thread Parse user-entered expressions into subs for an awk-like program
by xaprb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |