In the previous article, you used Perl to search for duplicate files on your computer. Full source code: Use File: dirwalk;
Use File: basename;
Use Data: dumper;
Use warnings;
Use strict;
My $ DW = new file: dirwalk;
My % files;
Fileparse_set_fstype ("mswin32 ");
$ DW-> onfile (
Sub {
My ($ file) = @_;
Push @ {$ files {basename ($ file)}-> {"paths" }}, $ file;
$ Files {basename ($ file)}-> {"num"} + = 1;
Return file: dirwalk: success;
}
);
My $ htrace;
Open $ htrace, '> trace.txt ';
Select $ htrace;
$ DW-> walk ('d:/old/perl ');
My @ newfiles;
While (My ($ K, $ v) = each % files)
{
If ($ V-> {"num"}> 1)
{
# Print $ K. "\ n ";
# Print dumper ($ V );
Push @ newfiles,
{
"Name" => $ K,
"Paths" = >$ V-> {"paths "},
"Num" => $ V-> {"num "}
}
}
}
# Print dumper (@ newfiles );
@ Newfiles = sort {($ A-> {"num"}) <=> ($ B-> {"num"})} @ newfiles;
Print dumper (@ newfiles );
Close $ htrace;