Tips_and_Hacks/MAST_tW_PDF_Updater/FilesForUpdates/Output.to.csv.pl

40 lines
1.1 KiB
Perl

use 5.12.0;
use Cwd;
my ($pwd, $^O, $d) = (cwd(), $^O, "\\");
if ($^O eq "darwin" || $^O eq "linux") {$d = "/"}
my $outDir = $pwd;
$outDir =~ s/\/([^\/]*)$//;
my ($originFile, $destinationFile) = ("$pwd${d}Output${d}tWs_for_PDF.txt", "$outDir${d}tWs_for_xT_PDF.txt");
my ($bk, $ch, $vs, $ulb, $tw, $dir, $ref);
open LOG, ">:utf8", "$pwd${d}Logs${d}log.log" or die "$!:\n$pwd${d}Logs${d}log.log";
open OUT, ">:utf8", $destinationFile or die "$!:\n$destinationFile";
say OUT "Book,Chapter,Verse,Term,Dir,Ref";
open (my $file, "<:utf8", "$originFile") or die "$originFile:\n$!";
while (my $line = <$file>) {
chomp $line;
#say LOG $line;
if ($line =~ /^([^:]*) (\d+):(\d+):$/) {
($bk, $ch, $vs) = ($1, $2, $3);
say LOG $line;
} elsif ($line =~ /^\[([^\]]*)\]\(([^\)]*)\)$/) {
($ulb, $tw) = ($1, $2);
if ($tw =~ /^([^\/]*)\/([^\/]*)$/) {
($dir, $ref) = ($1, $2)
}
say OUT "$bk,$ch,$vs,\"$ulb\",$dir,$ref"
}
}
close $file;
close OUT;
close LOG;
if ($^O eq "darwin"} {system 'open -a /Applications/BBEdit.app $destinationFile'}
print "\n\tDone.\n\n\tBe sure to rename the new file for New or Old Testament.";