Created
March 8, 2016 19:55
-
-
Save peter-leonov/bf85d36329a1fdc1abb5 to your computer and use it in GitHub Desktop.
dump perl based template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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