Tips_and_Hacks/MAST_tW_PDF_Updater/FilesForUpdates/Build_extract_NT.pl

54 lines
1.1 KiB
Perl

use 5.12.0;
use File::Slurp;
use File::Find ;
use FindBin '$Bin';
use Cwd ;
use utf8;
#use open IN => ":utf8", OUT => ":utf8";
use open IO => ":utf8";
my ($pwd, $d) = (cwd(), "\\");
if ($^O eq "darwin" || $^O eq "linux") {$d = "/"}
my $book;
my %books;
open LOG, ">$Bin${d}Logs${d}log.log" or die "$Bin${d}Logs${d}log.log: $!";
open (my $file, "<:utf8", "$Bin${d}User${d}tW_work_NT.txt") or die "$Bin${d}User${d}tW_work_NT.txt:\n$!";
while (my $line = <$file>) {
chomp $line;
if ($line =~ /^[^#][^\t]*\t([^\t]*)\t([^\t]*)\t([^\t]*)$/) {
$book = "$1";
$books{$book} = $book;
}
}
close $file;
say "Removing old Extract.txt";
unlink "$Bin${d}Temp${d}Extract.txt";
say "Building new Extract.txt";
open(OUT, ">:utf8", "$Bin${d}Temp${d}Extract.txt") or die "$!: $Bin${d}Temp${d}Extract.txt";
open ($file, "<:utf8", "$Bin${d}Temp${d}ULB_text.txt") or die "$Bin${d}Temp${d}ULB_text.txt:\n$!";
while (my $thisLine = <$file>) {
chomp $thisLine;
if ($thisLine =~ /^([^:]*) \d+:\d.*$/) {
if (exists $books{$1}) {
say OUT $thisLine;
}
}
}
close OUT;
close LOG;
say "Done."