perl-unicode

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

2004-12-27 11:51:59
Radoslaw Zielinski <radek(_at_)karnet(_dot_)pl> 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.


<Prev in Thread] Current Thread [Next in Thread>