Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Bug : eval and accent

by angiehope (Pilgrim)
on Nov 16, 2007 at 10:37 UTC ( [id://651163]=note: print w/replies, xml ) Need Help??


in reply to Bug : eval and accent

Hi! Same results here (Perl 5.8.8 on Slackware linux 12.0).
perl -w 651153.pl Eval buggy code ERR = Unrecognized character \xE9 at (eval 1) line 1. DONE Eval good code Use of uninitialized value in concatenation (.) or string at 651153.pl + line 15. string is : DONE
Since the file was encoded in ISO-8859, I converted it to utf-8, but with similar results. Then I added "use utf8;" as first line - and the script worked:
Eval buggy code DONE Eval good code string is : new eval done DONE
So, if anyone wants to use non-ascii characters for variable names, you should save the script as utf8 text file and include "use utf8;" Have a nice day!

Replies are listed 'Best First'.
Re^2: Bug : eval and accent
by sylvanus_monachus (Novice) on Nov 16, 2007 at 13:39 UTC

    The bug is not "accent in variable" The bug is that in second eval the perl lexer can't parse normal variable anymore...Eval is useful to execute buggy code ... that's why i use it, because the code comes from user and he can always put "Unrecognized character"

    And your are rigth , the way to solve the bug "accent in variable" is this way :

    use Unicode::String; my $code1='my $var_with_é_accent=5;print "var is $var_with_é_accent";' +; $code1="use utf8;$code1"; $code1=Unicode::String::latin1($code1)->utf8; print "\nEval buggy code\n"; eval "$code1"; print "ERR = $@" if ($@);; print "DONE\n"; my $string; my $code2='$string="new eval done";'; print "\nEval good code\n"; eval $code2; print "ERR = $@" if ($@); print "string is : $string\n"; print "DONE\n";
Re^2: Bug : eval and accent
by ikegami (Patriarch) on Nov 16, 2007 at 19:19 UTC

    The bug exists with use utf8 too.

    use strict; use warnings; use Encode qw( encode ); use HTML::Entities qw( decode_entities ); # This eval should have no effect on subsequent evals. eval encode('utf-8', decode_entities( 'use utf8; my $var_with_♥_non_word;' )); my $string = 'abc'; eval '$string = "def"; 1' or die; if ($string ne 'def') { print("BUG! string should be 'def' but is '$string'\n"); } else { print("No bug\n"); }
    BUG! string should be 'def' but is 'abc'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://651163]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-19 11:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found