in reply to unicode strings without decoding or warnings or corruption

Answering myself again

sub fixUTFness { use Data::Visitor::Callback; my $decodeVisitor = Data::Visitor::Callback->new( ignore_return_values => 1, value => sub { utf8::decode($_); return }, ); $decodeVisitor->visit( @_ ); }

then you get stuff like  print "Foo \x{2014} Bar"; and it all works

Replies are listed 'Best First'.
Re^2: unicode strings without decoding or warnings or corruption
by Corion (Patriarch) on May 13, 2012 at 11:30 UTC

    How is your code a solution, given the stated (and weird) restriction of

    I do not want to iterate over my huge hash of hashes to Encode::decode('UTF-8')

    While I don't doubt its correctness, if you are really the same person as the original poster, can you maybe explain how your approach of using Data::Visitor is not iterating over your hash?

      How is your code a solution, given the stated (and weird) restriction of

      I looked through my stuff and found that snippet to iterate over an arbitrary structure -- I thought I would have to write something from scratch

        OK--you lost me there. Why can't you use decode? Using your first snippet, I got:
        #!/usr/bin/perl use strict; use warnings; use Encode; require Encode::Detect; my $data = "Foo \xE2\x80\x94 Bar"; my $utf8 = decode("Detect", $data); binmode STDOUT, ":encoding(UTF-8)"; print $utf8;
        What's lame about that?