develooper Front page | perl.perl5.porters | Postings from April 2012

[perl #112532] eval( Dumper( 'Latin1' ) ) can result in malformed UTF8

Thread Next
From:
Sebastian Willert via RT
Date:
April 21, 2012 10:49
Subject:
[perl #112532] eval( Dumper( 'Latin1' ) ) can result in malformed UTF8
Message ID:
rt-3.6.HEAD-4610-1334869950-1693.112532-15-0@perl.org
Taken from https://metacpan.org/module/perlunifaq#Data::Dumper-doesnt-
restore-the-UTF8-flag-is-it-broken-
---
Data::Dumper doesn't restore the UTF8 flag; is it broken?

No, Data::Dumper's Unicode abilities are as they should be. There have 
been some complaints that it should restore the UTF8 flag when the data 
is read again with eval. However, you should really not look at the 
flag, and nothing indicates that Data::Dumper should break this rule.
Here's what happens: when Perl reads in a string literal, it sticks to 8 
bit encoding as long as it can. (But perhaps originally it was 
internally encoded as UTF-8, when you dumped it.) When it has to give 
that up because other characters are added to the text string, it 
silently upgrades the string to UTF-8. If you properly encode your 
strings for output, none of this is of your concern, and you can just 
eval dumped data as always.
---

Adding "utf8::upgrade( $last );" after the eval() line restores the flag 
and will lead to a passing test. HTH

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=112532

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About