use utf8;
use open ':std', ':utf8';
use feature 'unicode_strings';
...
for my $file ( @files ) {
open my $FH, '<', $file or die "Cannot open '$file' because: $!";
my $size = read $FH, my $data, -s $FH or die "Cannot read from '$file' because: $!";
$size == length( $data ) or die "Error reading from '$file'\n";
close $FH;
...
####
perl check-size.pl ./data.mixed
$VAR1 = {
'-s' => 282,
'length' => 226,
'read' => 226,
'tr' => 226
};
####
# Usage: perl5.36.3 check-size.pl ./data-mixed
use v5.32;
use warnings;
use warnings qw[ FATAL utf8 ];
use open qw[ :encoding(UTF-8) :std ];
use Data::Dumper;
local $Data::Dumper::Sortkeys = 1;
my $data = $ARGV[0]
or die qq[Give a file to count sizes of different kinds.\n];
my %stat = ( q/-s/ => -s $data );
open( my $fh, q/, $data )
or die qq/Cannot open $data to read: $!/;
my $string;
$stat{q/read/} = read( $fh, $string, $stat{q/-s/} )
or die qq/read from \$fh failed: $!/;
close( $fh )
or die qq/Could not close $data: $!/;
$stat{q/length/} = length( $string );
$stat{q/tr/} = $string =~ tr///c;
print( Dumper( \%stat ) );
####
Tj9EOzg3aHosYU9NbDtrLmZQcUt4M3l3dl8hR1IyLEpvNHJCMVdRVTVUaVpkQ2pMSVM2XzlFY1hl
dUhuIXRtLlkwRlZzZ3A/QS0tYk4/RDs4N2h6LGFPTWw7ay5mUHFLeDN5dwpGNVRuRUtsOGrwn5it
MGhQTzHvuI/ig6Mxc0lvQUx24KWsUyAgcHo2M0NiWuClr/CfpK9XVjJrR23wn5iSUnU3VWNI4KWv
YXFneDR34KWnWPCfmI85ZDHvuI/ig6Pwn6SjZk5Z8J+YrXlNSuClpmXgpajgpaZp4KWqdFFyREJG
NVRuRUtsOGrwn5itMGhQTzHvuI/ig6Mxc0lvQUx24KWsUyAgcHo2M0NiWuClr/CfpK9XVjIK