3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
9 # email brady@sparmy.com
12 # This is a perl script that will create a new ranslation spreadsheet
13 # file from a constant file and an old spreadsheet file. Output will
14 # go to newSpreadsheet.tsv and errors and message swill be logged to
19 # -Below will output the new spreadsheet:
20 # ./commonConstantsSpreadsheet.pl spreadsheet.tsv constants.txt
25 my $filenameOut = "newSpreadsheet.tsv";
26 my $logFile = "log.txt";
27 my $de = "\t"; # delimiter
33 my $constantRow = 6; # from spreadsheet, 0 is lowest
34 my $constantColumn = 1; # from spreadsheet, 0 is lowest
35 my $constantIdColumn = 0; # from spreadsheet, 0 is lowest
38 open(LOGFILE
, ">$logFile") or die "unable to open log file";
42 die "\nERROR: Too many parameters. Follow instructions found in buildLanguageDatabase.pl file.\n\n";
45 die "\nERROR: Need a parameter(s). Follow instructions found in buildLanguageDatabase.pl file.\n\n";
48 $inputSpreadsheet = $ARGV[0];
49 $inputConstants = $ARGV[1];
52 print LOGFILE
"ERROR: with parameters\n\n";
53 die "ERROR: with parameters\n\n";
57 open(OUTPUTFILE
, ">$filenameOut") or die "unable to open output file";
59 # place input files into arrays and chomp them
60 open(MYINPUTFILE
, "<$inputSpreadsheet") or die "unable to open file";
61 @spreadsheet = <MYINPUTFILE
>;
63 for my $var (@spreadsheet) {
66 open(MYINPUTFILE2
, "<$inputConstants") or die "unable to open file";
67 @constants = <MYINPUTFILE2
>;
69 for my $var (@constants) {
73 # first create header on new spreadsheet while removing it from spreadsheet array
74 for (my $i =0; $i < $constantRow; $i++) {
75 push (@newSpreadsheet, shift(@spreadsheet));
78 # place common constants into the spreadsheet array
79 my $idCounter = 1; # to assign constant id numbers
80 my $hitFlag; # flag to ensure ad new constants to spreadsheet
81 my @origSpreadConstants; # to keep track of removed constants later
82 my @finalSpreadConstants; # to keep track of removed constants later
83 my $first = 1; # to keep track of removed constants later
84 foreach my $var2 (@constants) {
86 $hitFlag = 0; # reset the hit flag
88 foreach my $var (@spreadsheet) {
90 my @tempArr = split($de,$var);
91 my $tempCons = @tempArr[$constantColumn];
93 # collect the original listing of constants during first loop
95 push(@origSpreadConstants,$tempCons)
98 if ($tempCons eq $var2) {
99 # add to array to keep track of removed constants
100 push(@finalSpreadConstants,$tempCons);
102 # create new id number
103 @tempArr[$constantIdColumn] = $idCounter;
104 my $newLine = join($de,@tempArr);
108 push (@newSpreadsheet,$newLine);
119 # constant is new, so add to spreadsheet
120 push (@newSpreadsheet,$idCounter.$de.$var2);
121 push (@finalSpreadConstants,$var2); # for later error checking
122 print LOGFILE
"ADDED: ".$var2."\n";
127 # send the removed constants to a log file
128 foreach my $var (@origSpreadConstants) {
129 if (!(withinArray
($var,@finalSpreadConstants))) {
130 print LOGFILE
"REMOVED: ".$var."\n";
134 # send the added constants to a log file
135 # this is redundant to hit method above
136 # no need for this method, so comment out
137 # foreach my $var (@finalSpreadConstants) {
138 # if (!(withinArray($var,@origSpreadConstants))) {
139 # print LOGFILE "ADDED: ".$var."\n";
143 # output the common constants
144 foreach my $var (@newSpreadsheet) {
145 print OUTPUTFILE
$var."\n";
156 # function to return whether a variable is in an array
157 # param - $variable @arr
158 # return - 1(true) or 0(false) integer
161 my($variable,@arr) = @_;
163 foreach my $tempVar (@arr) {
164 if ($tempVar eq $variable) {