in reply to Re: Hash comparing
in thread Hash comparing

Thank you!
Sorry if it looks like I am shouting this is the way I have always done my variables. At least for me they are easier to spot.
I was using code from a previous script and was not entirely sure what it was doing.

$FILE1PKG{$PACKAGE1[0]}{$PACKAGE1$FILE1PKG[1]} = $_;

Changed to
$FILE1PKG{$PACKAGE1[0]}=$PACKAGE1[1];


Also thank you for keeping it simple! I now have most things working and understand my errors much better!

As for the output being different I just used the first few lines of input and after posting realized I forgot to limit this for testing.


#!/usr/bin/perl # ## Define variables # $EMPTY=""; # ## Open file 1 for input and place contents into hash table # $FILENAME1 = shift; open(FILE1,"./$FILENAME1") || die "USEAGE ./checker file1 file2\n"; while(<FILE1>){ @PACKAGE1 = split(',',$_,2); #$FILE1PKG{$PACKAGE1[0]}{$PACKAGE1[1]} = $_; $FILE1PKG{$PACKAGE1[0]}=$PACKAGE1[1]; } close FILE1; # ## Open file 2 and compare the two this will create several outputs # $FILENAME2 = shift; open(FILE2,"./$FILENAME2") || die "USEAGE ./checker file1 file2\n"; while(<FILE2>){ @PACKAGE2 = split(',',$_,2); $FILE2PKG{$PACKAGE2[0]}=$PACKAGE2[1]; } close FILE2; # ## Read in hash and do comparisons # for $MASTERPKG ( keys %FILE1PKG ){ print "FILE1 PACKAGE: $MASTERPKG VERSION: ",$FILE1PKG{$MASTERPKG +}; print "FILE2 PACKAGE: $MASTERPKG VERSION: ",$FILE2PKG{$MASTERPKG +}; $VERSION1 = $FILE1PKG{$MASTERPKG}; $VERSION2 = $FILE2PKG{$MASTERPKG}; #print "\nVERSION1: $VERSION1 VERSION2: $VERSION2\n"; if ($VERSION1 eq $VERSION2) {print "SAME\n"}; if ($VERSION2 eq $EMPTY) {print "MISSING PACKAGE\n"}; if (($VERSION1 ne $VERSION2) && ($VERSION2 ne $EMPTY)) {print "DIFFER +ENT\n"}; }


All seems to be working as expected!

I also use caps when testing again I find it makes the output I am looking for stand out more

All who have responded thank you for your time and efforts!
Duck