in reply to Re^6: XML::Twig and file encoding
in thread XML::Twig and file encoding

hello, sorry to keep harping on this, but I continue to experience character mishaps when using XML::Twig.

The files are UTF8. They contain things like smart quotes, n-dashes, special spaces, etc. When I resave them I set UTF8:

   open(NEW,'>:encoding(UTF-8)', $outfile)

But then those special characters turn to gibberish. So "0-9" becomes "0–9"

My Twig setup:

my $twig= XML::Twig->new( comments => 'keep', keep_encoding => 1, pretty_print => 'indented', twig_handlers => { ...} );

Sorry to be slow here but I'm at a loss as to how to do this properly. (I did read the topics suggested but they seem to suggest encoding/decoding, and then it says not to do it if you don't want them encoded.)

Thanks, Scott

Replies are listed 'Best First'.
Re^8: XML::Twig and file encoding
by slugger415 (Monk) on Sep 18, 2014 at 15:09 UTC

    hm I seem to be getting better results by removing 'keep_encoding'... that doesn't make sense, so I'm clearly not understanding how that's supposed to work.

    forward...