Leser: 2
3 Einträge, 1 Seite |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#!/usr/bin/perl use strict; use warnings; use Digest::MD5 'md5_hex'; my $basepath='./data/'; my @files=map{"$_-tmp.lst"}(1..3); print "@files\n"; my %lines; for my $file (@files) { open(my $data,'<',$basepath.$file) or die "Konnte $file nicht oeffnen ($!)\n"; my $cnt=0; while(my $line=<$data>) { $cnt++; my $md5=md5_hex($line); my $pos={file=>$file, line=>$cnt}; if(exists($lines{$md5})) { push(@{$lines{$md5}},$pos) } else { $lines{$md5}=[$pos]; } } close($data); } my @doubles; while(my($key,$data)=each(%lines)) { if(@$data>1) { push(@doubles,$data) } } undef(%lines); @doubles=sort{$a->[0]->{file} cmp $b->[0]->{file} or $a->[0]->{line} <=> $b->[0]->{line}}@doubles; print "gefundene Doppelte:\n"; print '-'x10,"\n"; for my $double (@doubles) { for my $line (@$double) { print ' '.$line->{file}.' -> '.$line->{line}."\n"; } print '-'x10,"\n"; }
3 Einträge, 1 Seite |