http://qs321.pair.com?node_id=651171


in reply to Bug : eval and accent

Leaving aside the eval bug, if you wanted to make this code work, that's what the use utf8 pragma is for (permitting utf8 chars in the script source). It's lexically scoped, so you'll want it in each eval, so you could prepend it to the source code.
#!/usr/bin/perl use strict; use warnings; use utf8; my $var_with_é_accent = 10; print "var is $var_with_é_accent\n";
works fine on my perl 5.8.8 system. Maybe this helps you in the short term?

Replies are listed 'Best First'.
Re^2: Bug : eval and accent
by SFLEX (Chaplain) on Nov 16, 2007 at 12:30 UTC
    your code does not work for me on "Perl ActiveState v5.8.8 built for MSWin32-x86-multi-thread OS Windows XP"
    Im getting Error "Unrecognized character \xE9 at Untitled line 6"
    I wounder if this is an ActiveState issue.
      That error would arise if the file containing the script is not written/stored as utf8 data -- the accented character would need to be a two byte sequence 0xc3 0xa9 in order to be the utf8 version of é.

      0xE9 is the cp1252/iso-8859-1 (single-byte) version, and having that form of the character in a script file that also has "use utf8" is a problem with the file, not with perl.

      Hmm...are you sure the file in in utf8? E9 is latin1 for e-acute.

      Can you dump the hex values and check? (or just try code below).

      If your users are entering latin-1, then you could use the Encode module to shift the script to utf8.

      #!/usr/bin/perl use strict; use warnings; use Encode; use utf8; my $code = <<"EOLATINCODE"; my \$var_with_\xE9_accent = 10; print \"var is \$var_with_\xE9_accent\\n\"; EOLATINCODE $code = decode('latin1', $code); print "CODE is $code\n"; eval $code; if ($@) { print "DIED: $@\n"; }
      You don't seem to need 'use utf8' in the eval'd code in this case, but you seem to need it in the containing script.
      your script must be in utf8, it is latin1 currently. Convert the script to utf8 and retry.
      Boris