develooper Front page | perl.perl5.porters | Postings from November 2011

Re: [perl #34905] Encode::encode and destruction of the argument

Thread Previous
From:
Brian Fraser
Date:
November 19, 2011 07:48
Subject:
Re: [perl #34905] Encode::encode and destruction of the argument
Message ID:
CA+nL+nYUtj33-L0qaqt8tGQqGd+XiAYECpUVzCKeM2iFJjsS8Q@mail.gmail.com
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About