1#!/usr/bin/perl 2# 3# Logical compare (i.e. diff) of two settings files. 4# 5# For usage, see the usage statement in the code, below. 6# 7# ====================================================================== 8# (c) Copyright 1996,1997,1998,1999,2000,2001,2004,2006,2007,2008,2010, 9# 2011,2012 10# Whitehead Institute for Biomedical Research, Steve Rozen, 11# Andreas Untergasser and Helen Skaletsky 12# All rights reserved. 13# 14# This file is part of the primer3 suite. 15# 16# The primer3 suite is free software; you can redistribute it and/or 17# modify it under the terms of the GNU General Public License as 18# published by the Free Software Foundation; either version 2 of the 19# License, or (at your option) any later version. 20# 21# This software is distributed in the hope that it will be useful, 22# but WITHOUT ANY WARRANTY; without even the implied warranty of 23# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24# GNU General Public License for more details. 25# 26# You should have received a copy of the GNU General Public License 27# along with this file (file gpl-2.0.txt in the source distribution); if 28# not, write to the Free Software Foundation, Inc., 51 Franklin St, 29# Fifth Floor, Boston, MA 02110-1301 USA 30# 31# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 34# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35# OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 36# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 37# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 38# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 39# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 40# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 41# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 42# ====================================================================== 43 44 45 46use strict; 47use warnings "all"; 48use Getopt::Long; 49 50my $file1; 51my $file2; 52 53my %tags1; 54my %tags2; 55 56sub read_file($$) 57{ 58 my ($file, $tags) = @_; 59 open IN, $file or die "open $file: $!\n"; 60 # skip first line 61 my $line = <IN>; 62 while ($line = <IN>) { 63 chomp($line); 64 # skip empty lines and comments 65 if ($line =~ /^\s*$/) { next; } 66 if ($line =~ "^#") { next; } 67 unless ($line =~ /(\S*)=(.*)/) { print STDERR "wrong line format: $line\n"; next; } 68 my $tag = $1; 69 my $value = $2; 70 $tags->{$tag} = $value; 71 } 72 close IN; 73} 74 75if (!GetOptions("file1=s" => \$file1, "file2=s" => \$file2) || !defined($file1) || !defined($file2)) { 76 die "\nUsage:\n" 77 . "$0 -file1 <filename1> -file2 <filename2>\n"; 78} 79 80read_file($file1, \%tags1); 81read_file($file2, \%tags2); 82 83my @only1; 84 85# cmp tags1 with tags2 print anything common different 86print "Common tags with different values:\n"; 87foreach my $tag (sort (keys %tags1)) { 88 if (defined($tags2{$tag})) { 89 if ($tags1{$tag} ne $tags2{$tag}) { 90 print "\t$tag:\n\t\t$file1: $tag=$tags1{$tag}\n\t\t$file2: $tag=$tags2{$tag}\n" 91 } 92 } else { 93 push(@only1, $tag); 94 } 95} 96 97print "Tags that exist only in $file1:\n"; 98foreach my $tag (@only1) { 99 print "\t$tag=$tags1{$tag}\n"; 100} 101 102print "Tags that exist only in $file2:\n"; 103foreach my $tag (keys %tags2) { 104 if (!defined($tags1{$tag})) { 105 print "\t$tag=$tags2{$tag}\n"; 106 } 107} 108 109 110 111 112 113 114