in reply to Re^2: Counting bytes in a Unicode document
in thread Counting bytes in a Unicode document

Yes, -s is just another way to stat.

For example, one could write the following:

defined( my $s = -s $qfn ) or die( "Can't stat `$qfn`: $!\n" ); ... $s ...

But it could also be written as follows:

stat( $qfn ) or die( "Can't stat `$qfn`: $!\n" ); ... -s _ ...

or

defined( my $s = ( stat( $qfn ) )[ 7 ] ) or die( "Can't stat `$qfn`: $!\n" ); ... $s ...

Replies are listed 'Best First'.
Re^4: Counting bytes in a Unicode document
by etj (Priest) on Oct 15, 2024 at 12:39 UTC
    It's worth also mentioning the idiom of stat $file; ... (stat(_))[7] to use the result of the last stat.

      If it's worth mentioning, it's as something to avoid. -s _ is a million times more readable than +(stat(_))[7].

        The point, which regrettably you missed, wasn't the (stat etc)[n] idiom. It's the use of _ as an argument to these operations to reuse the cached results of the last one.