On Sat, Nov 19, 2011 at 12:51 PM, James E Keenan via RT <
perlbug-followup@perl.org> wrote:
> On Sun Apr 10 06:59:44 2005, perl-5.8.0@ton.iguana.be wrote:
>
> >
> > When using Encode I was unpleasantly surprised by this:
> >
> > perl -MEncode -wle '$a="abcd"; encode("utf8", $a, Encode::FB_CROAK);
> > print "a=<$a>\n"'
> > a=<>
> >
> > So encode() destroys its argument.
>
> More precisely, it destroys its argument when Encode::FB_CROAK is
> provided as the third argument to encode().
>
> ###
> $ perl -MEncode -wle '$a="abcd"; encode("utf8", $a); print "a=<$a>\n"'
> a=<abcd>
>
> $ perl -MEncode -wle '$a="abcd"; encode("utf8", $a, Encode::FB_DEFAULT);
> print "a=<$a>\n"'
> a=<abcd>
>
> $ perl -MEncode -wle '$a="abcd"; encode("utf8", $a, Encode::FB_CROAK);
> print "a=<$a>\n"'
> a=<>
> ###
>
This is actually in the docs though; See the part about Encode::LEAVE_SRC:
"If the Encode::LEAVE_SRC bit is not set, but CHECK is, then the second
argument to encode() or decode() may be assigned to by the functions. If
you're not interested in this, then bitwise-or the bitmask with it."
So this isn't a bug.
Thread Previous