in reply to Re: question about Encode::decode('iso-8859-1', ...)
in thread question about Encode::decode('iso-8859-1', ...)

thanks, but do you mean "may return 0 ..." instead of "may return 1 ..." ?
  • Comment on Re^2: question about Encode::decode('iso-8859-1', ...)

Replies are listed 'Best First'.
Re^3: question about Encode::decode('iso-8859-1', ...)
by ikegami (Patriarch) on Mar 07, 2009 at 05:42 UTC

    Well, it can return both :)

    It can return zero for any encoding other than US-ASCII and iso-8859-1.

      Don't think so. Could you provide an example?

      For "any encoding other than US-ASCII and iso-8859-1" to matter while decoding, you'd need wide characters, in which case Perl will croak with "Wide character in subroutine entry at .../Encode.pm line..." before returning anything. Any non-wide characters will simply be treated as iso-8859-1, because decode('iso-8859-1',...) is telling Perl they are.

        Here's a test that works with single-byte encodings:

        >perl -MEncode -wle"for (0..255) { print if chr ne decode($ARGV[0], ch +r) }" iso-8859-1 >perl -MEncode -wle"for (0x20..0x7E,0x0A..0xFF) { print if chr ne deco +de($ARGV[0], chr) }" iso-8859-2 161 162 163 165 166 169 ...

        Here's a UTF-8 example:

        >perl -MEncode -wle"$chr=qq{\342\231\240}; print 'diff' if $chr ne dec +ode('UTF-8', $chr)" diff