Open borisdaeppen opened 6 years ago
Datei-Liste erstellen in dos:
dir /s /b test > list.txt
evtl löst einfach ein korrektes encoding das problem:
my @content = read_file( $filepath, binmode => ':encoding(cp1252)' ) ;
#my @content = read_file( $filepath, binmode => ':utf8' );
also evtl. so:
my $encoding = $^O eq 'MSWin32' ? 'cp1252' : 'utf8';
say "Encoding: $encoding <";
binmode(STDOUT, ":encoding($encoding)" );
oder in ein Konfig-File auslagern!
this script reproduces the problem:
use strict;
use warnings;
use feature 'say';
use utf8;
use File::Slurp;
# works
my @lines = read_file( "C:/Users/user/Desktop/strawberry-perl-5.22.3.1-64bit-portable/README.txt", binmode => ':utf8' );
say 'the file has ' . scalar @lines . ' lines.';
# crashes
my @lines = read_file( "C:/Users/user/Desktop/strawberry-perl-5.22.3.1-64bit-portable/README.txt\r", binmode => ':utf8' );
say 'the file has ' . scalar @lines . ' lines.';
\r
is no problem when it is in a file, but it is a problem when passed as part of a filename!
So I think it is good practice to always check for \r
before passing to read_file
, because otherwise this nasty message appears:
' - sysopen: Invalid argument at crash.pl line 11.ry-perl-5.22.3.1-64bit-portable/README.txt
mention dir /s /b test | findstr /i "\.php$"> list.txt
in docs
https://stackoverflow.com/questions/650743/in-perl-how-to-remove-m-from-a-file/18062068#18062068