http://qs1969.pair.com?node_id=985845

choroba has asked for the wisdom of the Perl Monks concerning the following question:

Most honourable brothers and sisters in Perl. At work, we are having issues with substr. It returns strange values when called on the special variable $1.
The following code creates the test script and runs it:
use strict; use warnings; open my $PL, '>', 'utf2.pl' or die $!; print {$PL} << '__PL__'; ########################################################## use strict; use warnings; binmode STDOUT, ':utf8'; binmode STDIN, ':utf8'; while (my $line = <>) { if (my ($word) = $line =~ /^(.+)$/) { my $one = substr($1, 0, 1); # doesn't work my $w_one = substr($word, 0, 1); # works print "'$one' = '$w_one'\tat $line" unless $one eq $w_one; } } ########################################################## __PL__ open my $OUT1, '>', 'utf1' or die $!; print {$OUT1} map chr hex, qw/61 61 c5 99 0a c4 8d 0a 61 61 c5 99 0a/; close $OUT1; open my $OUT2, '>', 'utf2' or die $!; print {$OUT2} map chr hex, qw/c4 8d 0a 61 61 c5 99 0a c4 8d 0a/; close $OUT2; system "$^X utf2.pl < utf1"; print "\n"; system "$^X utf2.pl < utf2";
The output is (tested in blead 5.17.3, on x86_64-linux-thread-multi):
'�' = 'č'       at č

'aař' = 'a'     at aař
'č�' = 'č'      at č
Do you have any explanation? Should I submit a bugreport?

Update: Thanks all, bugreport sent.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ