Thanks a lot guys for your valuable comments.

Now that I have read the files (to be compared for uniqueness)into hashes and pushing the hashes into an array, I am trying to compare the uniqueness of the hashes. For that I have done the following:

use Data::Compare; use Data::Dumper; my $i = 0; my $y = 0; my $flag; my $x = 1; my @aoh; my @dupAoh; print "Tell me dude/dudette where are the log files: " , " \n"; $Location1 = <STDIN>; chomp $Location1; #print "And where would you like to put the processed results: " , "\n +"; #$Location2 = <STDIN>; #chomp $Location2; $UserInputDir = $Location1; opendir DH, $UserInputDir or die "Cannot open $UserInputDir: $!"; @files = readdir DH; closedir DH; foreach $file (@files) { next if $file=~/^\./; print "creating hash for $file....\n"; %filehash1 = filetohash($Location1.'\\'.$file); push @aoh, \%filehash1; #print Dumper(\\%filehash1); $x++; } print scalar(@aoh)."\n"; @dupAoh = @aoh; #print Dumper(\@dupAoh); foreach $val (@aoh) { #print "$val and $val++"; %hashValue1 = pop(@dupAoh); for ($i = 0; $i < scalar(@dupAoh); ++$i){ %hashValue2 = @aoh[i]; #print Dumper(\\%hashValue1); #print Dumper(\\%hashValue2); Compare(\%hashValue1, \%hashValue2) ? "identical \n" : "not identi +cal.\n"; #compHash(\%hashValue1, \%hashValue2); } } sub compHash{ my %filehash1 = shift; my %filehash2 = shift; for $key (keys %filehash1) { if($filehash2{$key} == 1){$flag = 1;}else{$flag = 0; last;} + print "Flag value is $flag \n"; } ($flag == 1) ? print "Yooohoo exactly same \n" : print "Not Same Alas! +!!\n"; } sub filetohash { my $counter; my $file = shift; my %filehash; open(FILE, "< $file") || die $!; while (<FILE>) { chomp $_; s/^ *//; s/ *$//; $filehash{$_} = 1; $counter++; } print "counted $counter lines for file $dir\n"; return \%filehash; }

I am trying with one of my own functions and have tried data::compare module as well, about which I didn't get much time to play with.

I have copied the array of hashes into another array. From the duplicate array I am popping the hashes (in turn the size of array reducing with each pass) and comparing it with the second hash element onwards of the original array. Basically, for a give 10 hashes I want to compare 1st hash with subsequent 9 hashes and then in next pass 2nd hash with subsequent 8 hashes. Please let me know what wrong I am doing or my logic is skewed.

Thanks, Xhings


In reply to Re^2: Unique Hash name for each pass by Xhings
in thread Unique Hash name for each pass by Xhings

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.