Last active
August 29, 2015 14:22
-
-
Save peter-leonov/37445d1c1904dd5ad75c to your computer and use it in GitHub Desktop.
tiny aka small aka simple aka plain perl template "engine"
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 | |
# use: 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