Created
September 12, 2017 05:46
-
-
Save Caaz/34f542a26db92685a97a39eb2c8e39ef to your computer and use it in GitHub Desktop.
Markdown compiler for simple variable substitution
This file contains hidden or 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 warnings; | |
use strict; | |
use Caaz::Prompt; | |
if($ARGV[0]) { | |
my (@lines, %map); | |
open FILE, "<$ARGV[0]"; | |
chomp(@lines = <FILE>); | |
close FILE; | |
for my $line (@lines){ | |
while($line =~ /\{(\w+?)\}/) { | |
my $key = $1; | |
unless($map{$key}) { | |
echo($line); | |
$map{$key} = ask($key); | |
} | |
$line =~ s/\{$key\}/$map{$key}/gs; | |
} | |
} | |
open EXPORT, ">$ARGV[1]"; | |
print EXPORT join "\n", @lines; | |
close EXPORT; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment