forked from webdetails/ccc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
repl-scripts.pl
41 lines (30 loc) · 998 Bytes
/
repl-scripts.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl
# USAGE:
# for file in *.txt; do ./repl-scripts.pl $file list.input > $file.out;done;
use strict;
use warnings;
my $format = " <script type=\"text/javascript\" src=\"../package-res/#value#.js\"></script>";
my $placeholderBeg = "<!-- \@SCRIPTSBEG\@ -->";
my $placeholderEnd = "<!-- \@SCRIPTSEND\@ -->";
##print STDERR "replacing tokens in " . $ARGV[0];
##print STDERR " with contents of " . $ARGV[1] . "\n";
open(ITEMLIST, $ARGV[1]) or die("Listing file not found");
my $contents = "";
while(<ITEMLIST>) {
my $item = $_;
$item =~ s/^\s*|\s*$//g;
if ($item ne "") {
my $row = $format;
$row =~ s/#value#/$item/g;
$contents = "$contents\n$row";
}
}
close ITEMLIST;
##print STDERR "$contents";
open(SRC, $ARGV[0]) or die("base file not found");
undef $/;
my $filecontent = <SRC>;
close SRC;
$/ = "\n"; #Restore normal read line by line behaviour
$filecontent =~ s/^(\s*$placeholderBeg)(.*?)(\s*$placeholderEnd)/$1$contents$3/smg;
print $filecontent;