From e4c489ce8fa76c385b4426be393a7cb8dbff07ff Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 20 Apr 2019 00:59:42 +0200 Subject: [PATCH] Finish finddup This doesn't look like it ever worked. Now it does. --- finddup | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) mode change 100644 => 100755 finddup diff --git a/finddup b/finddup old mode 100644 new mode 100755 index 5ed6a26..a108cf3 --- a/finddup +++ b/finddup @@ -6,7 +6,7 @@ finddup - yet another tool for finding duplicates =cut -use v5.10; +use v5.20; no autovivification 'fetch'; use File::Find; use File::stat; @@ -25,17 +25,17 @@ find(sub { unless ($files->{$size}{$hash}) { $files->{$size}{$hash} = []; } - push $files->{$size}{$hash}, { path => $File::Find::name, - size => $size, - dev => $st->dev, - ino => $st->ino, - }; + push $files->{$size}{$hash}->@*, { path => $File::Find::name, + size => $size, + dev => $st->dev, + ino => $st->ino, + }; } - }, - $filesdir + }, + $dir ); -for my $size (keys $files) { +for my $size (keys $files->%*) { if (@{ $files->{$size}{""} } == 1) { next; } @@ -46,16 +46,14 @@ for my $size (keys $files) { unless ($files->{$size}{$hash}) { $files->{$size}{$hash} = []; } - push $files->{$size}{$hash}, $file; + push $files->{$size}{$hash}->@*, $file; } delete $files->{$size}{""}; } - for my $hash (keys $files->{$size}) { + for my $hash (keys $files->{$size}->%*) { if (@{ $files->{$size}{$hash} } > 1) { - for my $file (@{ $files->{$size}{$hash} }) { - unless ($st->dev == $file->{dev} && $st->ino == $file->{ino}) { - say "$file->{path}"; - } + while (my ($i, $file) = each @{ $files->{$size}{$hash} }) { + say "$i: $file->{path}"; } say ""; } @@ -64,4 +62,3 @@ for my $size (keys $files) { # vim: tw=132 sw=4 expandtab -