http://www.perlmonks.org?node_id=985866


in reply to Substring giving strange results on $1 with utf8

I tried it with a different twist, using perl-5.17.2:
#!/usr/bin/perl BEGIN { $| = 1; $^W = 1; } use autodie; use strictures 1; use common::sense; open my $PL, '>', 'utf2.pl' or die $!; print {$PL} << '__PL__'; binmode STDIN, ":utf8"; binmode STDOUT, ":encoding(UTF-8)"; while (defined(my $line = <ARGV>)) { if (my($word) = $line =~ /^(.+)$/) { my $one = substr($word, 0, 1); my $w_one = substr($word, 0, 1); print "'$one' = 'one'\t at $line" if $one eq $1; print "'$w_one' = 'w_one'\t at $line" unless $w_one eq $1; } } __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";
Does that help?

Replies are listed 'Best First'.
Re^2: Substring giving strange results on $1 with utf8
by Anonymous Monk on Aug 07, 2012 at 03:45 UTC

    I tried it with a different twist, using perl-5.17.2: ... Does that help?

    How do you think that helps?

    The code no longer demonstrates the perl bug, how can that help?

    Typical Khen1950fx nonsense, poke the code with a stick and post the changes

      Typical AnonymousBug nonsense:);