Pam Derks wrote: > Hi all, > > I have 2 files that contain a filename and # of hits > I've split the contents of these 2 files into %hash1 and %hash2 > > I want to find out the difference in the # of hits > > can someone shed some light on the approach I should take. > > thanks in advance, > Pam > > > I've gotten this far: > > sample data: > FILE1 > arts.html 95 > arttherapy.html 102 > award.html 277 > bayart.html 1 > best.html 1 > > > FILE2 > arts.html 101 > arttherapy.html 103 > award.html 282 > bayart.html 2 > best.html 2 > splat.html 10 (note this is not in FILE1) > > > DESIRED OUTPUT: > arts.html 6 > arttherapy.html 1 > award.html 10 > best.html 1 > splat.html 10 > > > > > #!/usr/bin/perl -w > > $dir = "/dept/unxmkt/bin/hits/news/by_month"; > > chomp(@ARGV); > $file1 = shift(@ARGV); > $file2 = shift(@ARGV); > > print("$file1 $file2\n"); > > open(FILE1, "$dir/$file1.total") or die ("nope: $!"); > open(FILE2, "$dir/$file2.total") or die ("nope: $!"); > > > while(<FILE1>){ > my(%hash1, $key1, $value1); > ($key1, $value1) = chomp && split; > > $hash1{$key1} = $value1; > > for (keys %hash1){ > print("$hash1{$key1}\n"); > } > > } > > print("------------------------------\n"); > > > while(<FILE2>){ > my(%hash2, $key2, $value2); > ($key2, $value2) = chomp && split; > > $hash2{$key2} = $value2; > > for (keys %hash2){ > print("$hash2{$key2}\n"); > } > > }
You could just take and load using something like: hash{key}[0] - file1 [1] - file2 Then you only need read through once. When you do file1, you might set the second to 0, so you would have: $hash{key}[0] = 1111; [1] = 0; Then when reading the second, you could do something like: if ( ! defined $hash{key}[0] ) { $hash{key}[0] = 0; } $hash{key}[1] = 888; Now all values will be there and if you want to print and show differences, you won't get uninitialize value when using warnings. Wags ;) ********************************************************** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. **************************************************************** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]