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


in reply to Re: Why does Encode::Repair only correctly fix one of these two tandem characters?
in thread Why does Encode::Repair only correctly fix one of these two tandem characters?

TMTOWTDI.

I think the right-to-left pipeline I used to damage the characters for the purpose of the demonstration…

# <-- 3 <-- 2 <-- 1 $foo = encode('UTF-8', decode('Windows-1252', encode('UTF-8', $foo)));

…more clearly emulates what actually happens in the wild:  text is encoded in UTF-8, then wrongly decoded as if it were encoded in Windows-1252, then encoded again in UTF-8. I'm not sure what using the in-place convenience function Encode::from_to() lends to the clarity and effectiveness of the demonstration of the sequence of events.

FWIW, Encode::Repair uses Encode::encode() and Encode::decode(), not Encode::from_to().

Replies are listed 'Best First'.
Re^3: Why does Encode::Repair only correctly fix one of these two tandem characters?
by remiah (Hermit) on Aug 11, 2014 at 02:05 UTC

    I am so slow to understand the situation...

    I thought proper byte conversion from UTF-8 to cp1252 will solve the whole problem(between 1 and 2 of the pipeline).
    But the wrongly encoded text is already there in the wilderness, and no way back, right?

    Then I have no good idea...

      Sorry, I don't understand you.