in reply to beginner - if test on file flags

Both -s and -f are Perl unary operators documented in -X. From the page:

-s File has nonzero size (returns size in bytes).
-f File is a plain file.

Both use the default variable $_ if no arguments are specified, so the line in question first tests if the value in $_ corresponds to a file name, and if so, adds the size of the file to $total_size

Replies are listed 'Best First'.
Re^2: beginner - if test on file flags
by morgon (Priest) on Oct 15, 2010 at 15:48 UTC
    I have a related question: Is

    $total_size += -s _ if -f
    (a little bit) more efficient (at least on Linux) then
    $total_size += -s if -f
    because it only calls stat once or is there no difference?
      Slightly less efficent, so we could use _ instead:
      $total_size += -s _ if -f

      That is a matter for The Perl Implementors (and The Linux Implementors) to deal with.

      The Implementors Are Wise... wise beyond mortal understanding.

      “Be not concerned unnecessarily with efficiency,” he counseled, “for, verily, such concerns often produce something that is much more inefficient.”

Re^2: beginner - if test on file flags
by Anonymous Monk on Oct 15, 2010 at 23:00 UTC
    thanks!