Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I'm curious about the rest of the code. What happened to @sizes before that? Where can I see that?
    • Certainly. This was written by Abigail-II in answer the question Finding Top 10 Largest Files on PerlMonks. Since Abigail-II wrote it I have no doubt as to the correctness of the program:


      use strict;
      use warnings;
      no warnings qw /syntax/;

      open my $fh => "find / -type f |" or die;

      my @sizes = map {[-1 => ""]} 1 .. 10;

      while (<$fh>) {
          my $size = -s;
          next if $size < $sizes [-1] [0];
          foreach my $i (0 .. $#sizes) {
              if ($size >= $sizes [$i] [0]) {
                  splice @sizes => $i, 0 => [$size => $_];
                  pop @sizes;

      @sizes = grep {length $_ -> [1]} @sizes;
      printf "%8d: %s\n" => @$_ for @sizes;