vivapl has asked for the wisdom of the Perl Monks concerning the following question:

Searching for perl wisdom,

Having an array of filenames (from some directory) I need to check for their filesizes. How should I accomplish this?

eg:

for $tmpfilename (@files) { ........ }
Thanks in advance

Replies are listed 'Best First'.
•Re: Checking filesizes
by merlyn (Sage) on May 05, 2003 at 18:32 UTC
    I'm amused by the responses so far. All of them have used stat, when the simple -s filetest returns the same info:
    for $tmpfilename (@files) { defined(my $size = -s $tmpfilename) or warn("can't stat $tmpfilename +"), next; ... }

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: Checking filesizes
by artist (Parson) on May 05, 2003 at 18:08 UTC
      And for those of us not fond of line noise,
      my $size = (stat $file)[7];
      :)

      Makeshifts last the longest.

Re: Checking filesizes
by halley (Prior) on May 05, 2003 at 18:08 UTC
Re: Checking filesizes
by Huele-pedos (Acolyte) on May 05, 2003 at 18:09 UTC
    ... my @results = stat( $filename ); my $size = $results[7];
    Untested. But it is pretty straight forward. For more info use perldoc like so ...
    perldoc -f stat
Re: Checking filesizes
by vivapl (Acolyte) on May 05, 2003 at 19:48 UTC
    Thank you kindly! It worked great