#!/usr/bin/perl # sort by directory size use v5.12; use warnings; use File::Basename; use Text::CSV; my $csv = Text::CSV->new( { binary => 1 } ) or die "Cannot use CSV: " . Text::CSV->error_diag(); $csv->column_names(qw( fullpath filename mtime size digest )); my $database = "fileinfo.db"; open my $FH, q{<:encoding(utf8)}, $database or die "$database: $!"; say "connected to database '$database' successfully"; my %dir_info; while ( my $hr = $csv->getline_hr($FH) ) { $dir_info{ dirname( $hr->{fullpath} ) }->{SIZE} += $hr->{size}; $dir_info{ dirname( $hr->{fullpath} ) }->{COUNT}++; } foreach my $tmp_dir ( sort { $dir_info{$b}->{SIZE} <=> $dir_info{$a}->{SIZE} } keys %dir_info ) { say " $dir_info{$tmp_dir}->{SIZE} $tmp_dir ( $dir_info{$tmp_dir}->{COUNT})"; } __END__