http://www.perlmonks.org?node_id=1160099

polettix has asked for the wisdom of the Perl Monks concerning the following question:

Hi All!

I hit something weird I'd like to discuss with you. The behaviour below is there up until perl 5.20.2 at least, I didn't try it in anything more recent.

use strict; use warnings; use Encode qw< encode >; my $chars = "whatever"; print length($chars), " characters - initial string\n"; encode('UTF-8', $chars); print length($chars), " characters - first encode, no FB_CROAK\n"; encode('UTF-8', "$chars", Encode::FB_CROAK); print length($chars), " characters - second encode, FB_CROAK on, readonly string\n"; encode('UTF-8', $chars, Encode::FB_CROAK); print length($chars), " characters - third encode, FB_CROAK, on original string\n";
I would have expected that all the prints above would just say that the string $chars is 8 characters long... but perl thinks differently:
8 characters - initial string 8 characters - first encode, no FB_CROAK 8 characters - second encode, FB_CROAK on, readonly string 0 characters - third encode, FB_CROAK, on original string
So, it seems that if FB_CROAK is on and the string to encode is not readonly... it gets destroyed.

I tried with perl 5.8.8, 5.18.1 and 5.20.2, with the same results. I tried to look in the docs for Encode but to no avail. Tried to Google, but nothing. Tried to supersearch here... nothing.

Am I missing anything? Is this what's expected actually, and documented anywhere? Thanks!

perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Io ho capito... ma tu che hai detto?