in reply to Re: How to know to know if string is utf8 encoded or decoded.
in thread How to know to know if string is utf8 encoded or decoded.

Thank you for the reply.
below is the line which seems to have issue.
eval {$result = ConvertEncoding($string,"utf8",'MIME-Header')}
#convertEncoding uses below code to decode string

eval { $unicode = Encode::decode($from,$str); }; if ($@) { &ConvertEncodingError("($from -> utf8)\n$@"); return $str; }

Replies are listed 'Best First'.
Re^3: How to know to know if string is utf8 encoded or decoded.
by haj (Vicar) on Jul 26, 2019 at 17:55 UTC
    Wrapping the code in eval only makes sense if you ask decode to die if it can't decode:
    eval { $unicode = Encode::decode($from,$str,Encode::FB_CROAK); }; if ($@) { &ConvertEncodingError("($from -> utf8)\n$@"); return $str; }
    You should be aware that in case of a decoding error, $str will be overwritten.

      The third arg needs to be Encode::FB::CROAK | Encode::LEAVE_SRC since you don't want $from to change.

Re^3: How to know to know if string is utf8 encoded or decoded.
by Anonymous Monk on Jul 25, 2019 at 16:26 UTC

    eval { $unicode = Encode::decode($from,$str); #here $from is +'MIME-Header' }; if ($@) { &ConvertEncodingError("($from -> utf8)\n$@"); return $str; }

      "here $from is 'MIME-Header'"

      Shouldn't it be 'utf8'?


      The way forward always starts with a minimal test.

        No, it should not utf8 there.
        Thank you