Skip to content

Instantly share code, notes, and snippets.

@Caaz
Created September 12, 2017 05:46
Show Gist options
  • Save Caaz/34f542a26db92685a97a39eb2c8e39ef to your computer and use it in GitHub Desktop.
Save Caaz/34f542a26db92685a97a39eb2c8e39ef to your computer and use it in GitHub Desktop.
Markdown compiler for simple variable substitution
#!/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