develooper Front page | perl.unicode | Postings from September 2010

utf8 pragma, lexical scope

Thread Next
Michael Ludwig
September 9, 2010 13:01
utf8 pragma, lexical scope
Message ID:
No bug or problem, just something that works. :-) This script is in
UTF-8 (hence the utf8 pragma at the top), but it also has data in bytes,
which is taken care for by a lexical scope where utf8 is switched off.

          (o o)
use strict;
use warnings;
use utf8;
# binmode STDOUT, ':utf8';
my $str1 = 'Käse'; # Käse in UTF-8, looks wrong on a latin1 terminal
my $str2;
  no utf8;
  $str2 = 'Käse';
  print "$_\n" for $str1, $str2;
print "$_\n" for $str1, $str2;

It works fine in 5.10.1 and 5.12.1, regardless of STDOUT setting.

What does not work, however, is to have a variable $käse under utf8
and then try to refer to it from inside a "no utf8" block, using either
encoding. Without the utf8 pragma, identifiers are not allowed to have
funny characters. (Yes, it was a stupid exercise.)
Michael Ludwig

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About