forked from kb-dk/traces-of-historical-plagues
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcholera_i
executable file
·39 lines (33 loc) · 949 Bytes
/
cholera_i
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
#!/usr/bin/perl -w
use strict;
my $preposition = $ARGV[0] ? $ARGV[0] : 'i';
my $dir = 'yearly' . ( $preposition ne 'i' ? $preposition : '');
system("mkdir $dir");
system("rm $dir/*.text*");
for my $year (1848 .. 1858) {
system("touch ./$dir/$year\.text" );
}
if(open(my $pipe,'grep -aP \'[0123456789]\s((ch)|(k))olera\s' . $preposition . '\s\' trigrams/* | sort -n -k1.10|')) {
while(my $line = <$pipe>) {
# print $line;
chomp $line;
$line =~ m/^trigrams\/(\d+).text:.*/;
my $week = $1;
my $third_word = $line;
if($third_word =~s/^.+olera\s+$preposition\s+//) {
my $year = `grep $week\.text year_by_weekly.text`;
chomp $year;
$year =~ s/\sweek.*$//;
next if $year =~ m/weekly/;
next if $year =~ m/1847|1859|1860/;
if(open(my $olera,">>./$dir/$year".'.text')) {
print $olera "$third_word\n";
close $olera;
} else {
print STDERR
}
}
}
} else {
die "Cannot open $pipe: $!";
}