Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
dump perl based template
#!/usr/bin/perl
# usage: echo "hello <%= $USER %> <% if (true) { %>abc<%>%>" | perl template.pl > out.txt
for $key (keys %ENV) { ${$key} = $ENV{$key} }
$template = join("", <>);
$template =~ s/<%=/<% print /g;
@code = @text = split(/<%(.+?)%>/s, $template);
for (my $i = 0; $i <= $#code; $i+=2) { @code[$i] = "; print \@text[$i];" }
eval join(";", @code);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.