borisdaeppen / School-Code-Compare

Compare files containing text or code for similarity.
Other
0 stars 1 forks source link

windows patch #18

Open borisdaeppen opened 6 years ago

borisdaeppen commented 6 years ago

https://stackoverflow.com/questions/650743/in-perl-how-to-remove-m-from-a-file/18062068#18062068

foreach my $filepath ( @FILE_LIST ) {
    chomp( $filepath );
    chop($filepath) if ($filepath =~ m/\r$/); # deal with dos input
borisdaeppen commented 6 years ago

Datei-Liste erstellen in dos:

dir /s /b test > list.txt

borisdaeppen commented 6 years ago

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!

borisdaeppen commented 6 years ago

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

borisdaeppen commented 6 years ago

mention dir /s /b test | findstr /i "\.php$"> list.txt in docs