Created
July 9, 2018 13:56
-
-
Save scottw/435d47e1a03f83b2cd8698cf5dd1d008 to your computer and use it in GitHub Desktop.
An example of a no-dependency template in Perl
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/env perl | |
use strict; | |
use warnings; | |
# hydrate: poor man's templating | |
# | |
# usage: hydrate key1=value1 key2=value2 ... path/to/file.in > path/to/file.out | |
# | |
# substitutes all strings '{{key1}}' in file.in with 'value1' | |
my $file = pop @ARGV; | |
my %kv = map { split /=/ } @ARGV; | |
open my $fh, "<", $file | |
or die "Unable to open '$file': $!\n"; | |
while (my $line = <$fh>) { | |
$line =~ s/\{\{(\S+?)\}\}/$kv{$1}/g; | |
print $line; | |
} | |
close $fh; |
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
{ | |
"host": "{{mysql_host}}", | |
"username": "{{mysql_user}}", | |
"password": "{{mysql_pass}}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment