Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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?

In reply to Encode::FB_CROAK eating up strings? by polettix

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2023-09-30 13:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found