# Compare quarantine numbers against activated pacwest # Load Pacwest into array, search with quarantine numbers $log = "./comparison.log"; @gapratecenters = ( "ATWATER", "CHICO", "CORNING", "EXETER", "LINDSAY", "LOS BANOS", "MODESTO", "OAKDALE", "ORLAND", "PORTERVL", "RED BLUFF", "RIVERBANK", "TIPTON", "TULARE", "TURLOCK", "VISALIA", "WOODLAKE" ); ######################################################### ############### Open File Descriptors ################### ######################################################### $file1 = $ARGV[0] or die "First file not specified!\n"; $file2 = $ARGV[1] or die "Second file not specified!\n"; open(FILE1, $ARGV[0]) or die "$ARGV[0] does not exist\n"; open(FILE2, $ARGV[1]) or die "$ARGV[1] does not exist\n"; open(LOG, ">" . $log) or die "$log does not exist\n"; ######################################################### ################ Read Data From Files ################### ######################################################### @data1 = `grep 'A[cs]' $file1 | sed -e "s/\\x00//g"`; @data2 = `cat $file2 | sed -e 's/\\x00//g'|grep -v 'Active'|grep -v 'Ordered'|cut --delimiter=, -f 1`; shift @data2; # Remove header chomp @data1; # Remove newlines chomp @data2; # Remove newlines @gapratenumbers = highlight_gapratecenters(@data1); my ($active_tree, $available_tree); ######################################################### ############### Add Pacwest Data ######################## ######################################################### foreach (@data1) { s/\s+$//g; insert($active_tree, $_); } ######################################################### ################ Search Against Data #################### ######################################################### foreach (@data2) { if ($_) { @fields = split /,/; $isthere = search($active_tree, $fields[0]); if ($isthere) { foreach $gapratenumber (@gapratenumbers) { if ($fields[0] == $gapratenumber) { print "$fields[0] has conflicting status!\n"; } } } } } ###################################################### ############ Clean up the files ###################### ###################################################### close(FILE1); close(FILE2); close(LOG); #################################################### ########### Highlight Gap Rate Centers ############# #################################################### sub highlight_gapratecenters { @result; foreach(@_) { @lines = split /,/; $lines[6] =~ s/\s+$//g; foreach $location (@gapratecenters) { if ($lines[6] eq $location) { push(@result,$lines[0]); } } } return @result; } ############################################ # BINARY TREE DATA STRUCTURE # ############################################ sub insert { my($tree, $value) = @_; unless ($tree) { $tree = {}; # allocate new node $tree->{VALUE} = $value; $tree->{LEFT} = undef; $tree->{RIGHT} = undef; $_[0] = $tree; # $_[0] is reference param! return; } if ($tree->{VALUE} > $value) { insert($tree->{LEFT}, $value) } elsif ($tree->{VALUE} < $value) { insert($tree->{RIGHT}, $value) } # else { warn "duplicate insert of $value\n" } # XXX: no dups } sub search { my($tree, $value) = @_; return unless $tree; if ($tree->{VALUE} =~ m/$value/) { return $tree; } search($tree->{ ($value < $tree->{VALUE}) ? "LEFT" : "RIGHT"}, $value) } ######################################## # END BINARY TREE DATA STRUCTURE # ########################################