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.
I would have expected that all the prints above would just say that the string $chars is 8 characters long... but perl thinks differently: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";
So, it seems that if FB_CROAK is on and the string to encode is not readonly... it gets destroyed.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
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Encode::FB_CROAK eating up strings?
by SimonPratt (Friar) on Apr 11, 2016 at 10:48 UTC | |
Re: Encode::FB_CROAK eating up strings?
by Anonymous Monk on Apr 11, 2016 at 11:22 UTC | |
by polettix (Vicar) on Apr 11, 2016 at 12:14 UTC |
Back to
Seekers of Perl Wisdom