herda05 has asked for the wisdom of the Perl Monks concerning the following question:
getCount just does a keys <%hash> into scalar to get a count of keys. Problem is, perl thinks there are only 37585 lines in file1.Huh?while (<FH1>) { chomp; my $line = $_; #print __LINE__ . " $_\n"; my ($var1,$var2) = split(/:/,$line); $var2 = substr($var2,1); #remove 1st space results from substr $diffHash1{$var2} = $var2; } close(FH1); getCount(\%diffHash1); #$sclar = keys(%hash) my $cnt1 = getCount(\%diffHash1,'1'); print "Reading in $file2\n"; open FH2, "< $file1" || die "Counld not open $file2: $!"; while (<FH2>) { chomp; my $line = $_; my ($var1,$var2) = split(/:/,$line); $var2 = substr($var2,1); $diffHash2{$var2} = $var2; } close(FH2); print "Comparing $file1 and $file2\n"; my $cnt2 = getCount(\%diffHash2,'1'); print "Count in $file1: $cnt1\n"; print "Count in $file2: $cnt2\n"; if ($cnt1 gt $cnt2) { while (my($k1,$v1) = each(%diffHash1)) { my $line = $k1; if (!$diffHash2{$line}) { $resHash{$line} = $line; } } } else { while (my($k1,$v1) = each(%diffHash2)) { my $line = $k1; if (!$diffHash1{$line}) { $resHash{$line} = $line; } } }
which returns 37621. Alright, me thinks, maybe there are blank lines, or some other entries that I'm not coding for. So I sort the two files, then do a diff redirect and get 36 names that aren't in file2. Question is, where am I letting perl down in my code? How come perl isn't seeing all the jobs in file1?grep insert_job | wc -l
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Different counts between perl and grep
by Tanktalus (Canon) on Aug 29, 2009 at 05:13 UTC | |
|
Re: Different counts between perl and grep
by herda05 (Acolyte) on Aug 29, 2009 at 05:13 UTC | |
|
Re: Different counts between perl and grep
by bv (Friar) on Aug 29, 2009 at 14:38 UTC |