Tips_and_Hacks/MAST_tW_PDF_Updater/FilesForUpdates/CombineULBandNASBwithCodes.pl

75 lines
1.9 KiB
Perl
Raw Normal View History

2019-02-18 19:52:30 +00:00
# Combines most recent ULB with KJV with codes.
use 5.12.0;
use Cwd;
use FindBin '$Bin';
2019-02-18 19:52:30 +00:00
my ($pwd, $d) = ($Bin, "\\");
if ($^O eq "darwin" || $^O eq "linux") {$d = "/"}
2019-02-18 19:52:30 +00:00
# /Users/Henry/Documents/git.Door43/en_tw/ForPDF/FilesForUpdates/CombineULBandNASBwithCodes.pl
2019-04-10 20:29:39 +00:00
my ($ulb, $nasb) = ("$Bin${d}Temp${d}ULB_text.txt", "$Bin${d}Data${d}NASB_Strongs.txt");
2019-02-18 19:52:30 +00:00
my ($ref, $val, $textEditor);
my (%codes);
2019-04-10 20:29:39 +00:00
open LOG, ">:utf8", "$Bin${d}Logs${d}log.log" or die;
open OUT, ">:utf8", "$Bin${d}Temp${d}ULB_NASB_Strongs.txt" or die;
2019-02-18 19:52:30 +00:00
2019-02-19 21:01:01 +00:00
#say "\$pwd: $pwd${d}User${d}User_defaults.txt";
#say " /media/henry/92C6F7E3C6F7C58F/Users/henry/WA_Repo/Tips_and_Hacks/MAST_tW_PDF_Updater/FilesForUpdates/User/User_defaults.txt";
2019-03-21 17:32:11 +00:00
chdir $Bin;
2019-03-21 17:32:11 +00:00
my ($udf) = "User_defaults.windows.txt";
if ($^O eq "linux") {$udf = "User_defaults.linux.txt"}
elsif ($^O eq "darwin") {$udf = "User_defaults.mac.txt"}
open (my $defaults, "<:utf8", "$Bin${d}User${d}$udf") or die "$Bin${d}User${d}$udf:\n$!";
2019-02-18 19:52:30 +00:00
while (my $thisLine = <$defaults>) {
chomp $thisLine;
if ($thisLine =~ /^Text editor: (.*)$/) {
2019-04-10 20:29:39 +00:00
#say LOG "$thisLine";
2019-02-18 19:52:30 +00:00
$textEditor = $1;
}
}
#say "\$textEditor: $textEditor";
2019-02-18 19:52:30 +00:00
die "No text editor found" if $textEditor eq "";
close $defaults;
open (my $file, "<:utf8", "$nasb") or die "$nasb:\n$!";
while (my $line = <$file>) {
chomp $line;
if ($line =~ /^([^\t]*)\t(.*)$/) {
2019-02-18 19:52:30 +00:00
($ref, $val) = ($1, $2);
2019-02-21 22:26:29 +00:00
$ref =~ s/^Song of Solomon/Song of Songs/;
$codes{$ref} = $val;
2019-02-18 19:52:30 +00:00
}
}
open ($file, "<:utf8", "$ulb") or die "$ulb:\n$!";
while (my $line = <$file>) {
chomp $line;
2019-04-10 20:29:39 +00:00
#say LOG $line;
2019-02-18 19:52:30 +00:00
if ($line =~ /^([^\t]*)\t(.*)$/) {
($ref, $val) = ($1, $2);
if (exists $codes{$ref}) {
say OUT "$ref\t$val\n $codes{$ref}"
}
}
}
close OUT;
2019-03-22 17:27:03 +00:00
# say "Calling \$textEditor $textEditor";
if ($^O eq "darwin") {
2019-04-10 20:29:39 +00:00
system ("open -a $textEditor $Bin${d}Temp${d}ULB_NASB_Strongs.txt");
2019-02-18 19:52:30 +00:00
}
close LOG;
2019-04-10 20:29:39 +00:00
print "\n\tDone\n\n\tOutput is in $Bin${d}Temp${d}ULB_NASB_Strongs.txt\n\n";