1
|
#!/usr/bin/perl
|
2
|
|
3
|
use strict;
|
4
|
use warnings;
|
5
|
|
6
|
open my $fh, '<', $ARGV[0];
|
7
|
my @lines = <$fh>;
|
8
|
close $fh;
|
9
|
|
10
|
my $iDIW;
|
11
|
for (my $i=0; $i < @lines ; $i++) {
|
12
|
if ($lines[$i] =~ /^\s+distance_in_words:$/) {
|
13
|
$iDIW= $i;
|
14
|
last;
|
15
|
}
|
16
|
}
|
17
|
die unless $iDIW;
|
18
|
|
19
|
open $fh, '>', 'lang/'.$ARGV[0];
|
20
|
for (my $i=0; $i < $iDIW ; $i++) {
|
21
|
print $fh $lines[$i];
|
22
|
}
|
23
|
|
24
|
foreach my $x ('x_hours', 'x_days') {
|
25
|
my ($start, $end, $c);
|
26
|
for (my $i=$iDIW; $i < @lines ; $i++) {
|
27
|
my $line= $lines[$i];
|
28
|
if ($line =~ /^\s+($x:)$/) {
|
29
|
#print "$x $i\n";
|
30
|
$start= $i;
|
31
|
$c= $-[1]+1;
|
32
|
#print "$x $i $c\n";
|
33
|
} elsif ($start and substr($line, 0, $c) =~ /[^\s]/) {
|
34
|
$end= $i;
|
35
|
#print "$ARGV[0] $x $start $end\n";
|
36
|
for (my $i=$start; $i < $end ; $i++) {
|
37
|
(my $line= $lines[$i]) =~ s/^ //;
|
38
|
print $fh $line;
|
39
|
}
|
40
|
last;
|
41
|
}
|
42
|
}
|
43
|
die unless $end;
|
44
|
}
|
45
|
|
46
|
for (my $i=$iDIW; $i < @lines ; $i++) {
|
47
|
print $fh $lines[$i];
|
48
|
}
|
49
|
close $fh;
|