Re: "Undocumented feature" of Encode::{en,de}code()

[email protected] (Nick Ing-Simmons)
Newsgroups perl.unicode
Message-ID <[email protected]>
Radoslaw Zielinski <[email protected]> writes:
>Hello,
>
>What's the point of lines 151 and 167 in Encode.pm?  Respectively:
>
>    # sub encode
>    $_[1] = $string if $check;
>
>    # sub decode
>    $_[1] = $octets if $check;

>
>I really can't see a point in overwriting the input value...  Why only
>"if $check"?  


Part of the whole 'check' thing was to return the un-decodable 
part somehow. So return value is decoded (say) as far as possible.
And the undecoded part is left in original string.

The error handling stuff is still not as uniform as I would like.


>An example of evilness:
>
>  $ perl -MEncode -wle '$x=\"abc"; decode("us-ascii",$$x,1)'
>  Modification of a read-only value attempted at /usr/lib/perl5/5.8.6/athlon-pld-linux-thread-multi/Encode.pm line 167.
>
>Besides, the value is empty:
>
>  $ perl -MEncode -we '$x="abc"; decode("us-ascii",$x, 1); print $x' | wc
>        0       0       0

If you want to do in-place use from_to style - encode/decode return 
the result.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.