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

> the aforementioned stat solution is much more efficient

I suppose the -s in the OP's code does exactly the same.

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^3: Counting bytes in a Unicode document
by ikegami (Patriarch) on Oct 09, 2024 at 00:32 UTC

    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 ...
      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].