# returns the $limit largest files from the flist file, # full path to file in $name sub process_flist { my ($name, $limit) = @_; my ($nlines, $total, @lines, @size); open(my $fh, '<', $name) or die("Error opening file `$name': $!\n"); while (<$fh>) { my @f = split / /; # skip files that have a space or other whitespace # characters in their name next if @f > 10; # store file size in bytes and the full path to the file push @lines, $f[4] . '/' . $f[1]; } $nlines = scalar @lines; { # disable warnings because the array to be sorted has # the following format "12345/path/to/file" # Perl would complain this is not a number # but the <=> comparison operator will handle such # input properly # this is needed so the files can be sorted # with a single pass through # the flist file no warnings 'numeric'; $total = sum(@lines); $limit = min($limit, $nlines); @lines = (sort {$b <=> $a} @lines)[0 .. ($limit - 1)]; } # returns the number of files, their cumulative size, # and the $limit largest files return ($nlines, $total, @lines); }