cmdtest/replace_strings.pl
Johan Holmberg 136bb53a89 improve --version output
now showing a value like 1.4.20161008,
the same as the DEB package
2016-10-08 21:04:30 +02:00

31 lines
636 B
Perl
Executable File

#!/usr/bin/env perl
use strict;
my @replace;
while (@ARGV > 0 && $ARGV[0] =~ /^(\w+)=(.*)/) {
my ($old, $new) = ($1, $2);
push @replace, [$old, $new];
shift @ARGV;
}
if (@ARGV != 2) {
die "Usage: replace_strings K1=V1 ... Kn=Vn INFILE OUTFILE\n";
}
my ($infile, $outfile) = @ARGV;
open(my $f, '<', $infile) || die "open($infile)";
open(my $g, '>', $outfile) || die "open($outfile)";
while (my $line = <$f>) {
for my $entry (@replace) {
my ($old, $new) = @$entry;
$line =~ s/\$$old\$/$new/g;
}
print {$g} $line;
}
close($f) || die "close($infile)";
close($g) || die "close($outfile)";