Skip to content

Instantly share code, notes, and snippets.

@peter-leonov
Created March 8, 2016 19:55
Show Gist options
  • Save peter-leonov/bf85d36329a1fdc1abb5 to your computer and use it in GitHub Desktop.
Save peter-leonov/bf85d36329a1fdc1abb5 to your computer and use it in GitHub Desktop.
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