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.
  • @sizes = grep {length $_ -> [1]} @sizes; Specifically, what is {length $_ -> [1]} doing?

    From the docs:

    Evaluates the BLOCK or EXPR for each element of LIST (locally setting $_ to each element) and returns the list value consist- ing of those elements for which the expression evaluated to true. In scalar context, returns the number of times the expression was true.

    The most basic example is something like:

    perl -e '@foo = grep { $_ } (1,0,undef); print "@foo\n"'

    This goes though the list (1,


    "Cake or Death!" .... "Cake please"
    • Oh. Ow. Ouch! @size is not an array of file names but rather a line with file name, file size, etc. I might plead that I am a windows programmer but geez, even so, I should have realized that. My stumbling block was [1]. I couldn't see the relationship even knowing what -> was. Density^3. Thank you.

  • 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) {