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 simply sort and remove redundant entries
13 # from a list to maintain the manuallyAddedConstants.txt and the
14 # manuallyRemovedConstants.txt files.
18 # -Below command will simply sort and remove redundant entries from a list:
19 # ./sortCleanList.pl manuallyAddedConstants.txt
26 my $logFile = "log.txt";
27 my $filenameOut = "list.txt";
31 die "\nERROR: Too many parameters. Follow instructions found in sortCleanList.pl file.\n\n";
34 die "\nERROR: Not enough parameters. Follow instructions found in sortCleanList.pl file.\n\n";
37 $inputFile = $ARGV[0];
40 die "\nERROR: Problem with parameters. Follow instructions found in sortCleanList.pl file.\n\n";
43 # open log file and output file
44 open(LOGFILE
, ">$logFile") or die "unable to open log file";
45 open(OUTPUTFILE
, ">$filenameOut") or die "unable to open output file";
47 # if comparing, then open input file and store in array
48 open(MYINPUTFILE
, "<$inputFile") or die "unable to open file";
49 my @inputList = <MYINPUTFILE
>;
52 # remove blankl lines, windows characters, and chomp it
53 my @processInputList1;
54 foreach my $var (@inputList) {
56 # remove ^M characters (windows line feeds)
63 push(@processInputList1,$var);
67 my @processInputList2;
68 foreach my $var (@processInputList1) {
69 if (withinArray
($var,@processInputList2)) {
70 print LOGFILE
"Redundant variable removed: " . $var . "\n";
73 push (@processInputList2, $var);
78 my @sortedInputList = sortConstants
(@processInputList2);
81 foreach my $var (@sortedInputList) {
82 print OUTPUTFILE
$var . "\n";
94 # function to sort constant list
103 foreach my $var (@arr) {
104 if ($var =~ /^[a-z]/i) {
112 my @sortFirst = sort { lc($a) cmp lc($b) } @first;
113 my @sortLast = sort { lc($a) cmp lc($b) } @last;
115 push (@sortFirst, @sortLast);
116 my @sorted_arr = @sortFirst;
123 # function to return whether a variable is in an array
124 # param - $variable @arr
125 # return - 1(true) or 0(false) integer
128 my($variable,@arr) = @_;
130 foreach my $tempVar (@arr) {
131 if ($tempVar eq $variable) {