perl-unicode

Re: Use case for utf8::upgrade?

2010-04-07 18:27:47
* Gisle Aas <gisle(_at_)aas(_dot_)no> [2010-04-08 00:00]:
This fix was withdrawn from 5.12.0. Currently you have to "use
feature 'unicode_strings'" to get the sane behaviour in the
current lexical scope. Current 'perldoc unicode' also says:

      The "use feature 'unicode_strings'" pragma is intended to
      always, regardless of platform, force Unicode semantics
      in a particular lexical scope. In release 5.12, it is
      partially implemented, applying only to case changes. See
      "The "Unicode Bug"" below.

This means that the utf8::upgrade() advice also applies to
perl-5.12.0.

Oh right! That was it. (I couldn’t remember the specifics.)

Well, using `use feature 'unicode_strings';` and not upgrading
strings is a better strategy for code that doesn’t need to work
under earlier perl versions, since upgrading a string increases
memory consumption and can significantly slow down regex matches
against it.

Under older perls, it’s a question of getting the wrong results
in less time and memory, so there’s not an option.

If you want both, I guess you could do something like

    use constant UNICODE_BUG => ( $] < 5.012 );
    use if not UNICODE_BUG, feature => 'unicode_strings';
    # ...
    utf8::upgrade( $some_str ) if UNICODE_BUG;

(Note to readers who don’t already know: using a constant here
will cause either the conditional or the entire statement to get
optimised away depending on its truthiness, so that there won’t
be any runtime penalty for the conditionals.)

Regards,
-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>

<Prev in Thread] Current Thread [Next in Thread>