develooper Front page | perl.perl5.porters | Postings from May 2013

Re: [perl #117355] [lu]cfirst don't respect 'use bytes'

Thread Previous
From:
Karl Williamson
Date:
May 5, 2013 03:03
Subject:
Re: [perl #117355] [lu]cfirst don't respect 'use bytes'
Message ID:
5185CBD3.3060804@khwilliamson.com
On 03/25/2013 11:45 PM, Eric Brine wrote:
>
>
> On Mon, Mar 25, 2013 at 9:50 PM, Aristotle Pagaltzis <pagaltzis@gmx.de
> <mailto:pagaltzis@gmx.de>> wrote:
>
>     * Brian Fraser <perlbug-followup@perl.org
>     <mailto:perlbug-followup@perl.org>> [2013-03-26 01:50]:
>      > $_ = "\x{30cb}";
>      > use Devel::Peek;
>      > use bytes;
>      > Dump $_ for uc, lc, CORE::fc, ucfirst, lcfirst;
>      >
>      > ucfirst & lcfirst return a UTF-8 flagged scalar, while the first
>     three
>      > return bytes.
>
>     Is it worth fixing something to follow a semantic that itself is broken
>     as designed?
>
>     I’m not sure if we had an explicit consensus about bytes.pm
>     <http://bytes.pm> being highly
>     discouraged
>
>
> "and use of this module for anything other than debugging purposes is
> strongly discouraged."
>
>     , the way we had about encoding.pm <http://encoding.pm> deserving
>     deprecation,
>
>
> "This module is deprecated under perl 5.18. It uses a mechanism provided
> by perl that is deprecated under 5.18 and higher, and may be removed in
> a future version."
>
> At least publicly, it's not quite the same level.
>
>     but I would be happy if we could move it in that direction; and the
>     farther, the happier.
>
>
> Indeed. If you have to deal with a buggy module, should be using
> utf8::downgrade instead.
>

Attached is a patch that fixes the original report.  The code it changes 
is a small portion of this commit:

commit d54190f6ca0aac8b08bb59370c53932771933c40
  Author: Nicholas Clark <nick@ccl4.org>
  Date:   Sat Apr 29 15:55:51 2006 +0000

      lcfirst/ucfirst plus an 8 bit locale could mangle UTF-8 values
      returned by overloaded stringification.

I was the one who added the comments much later.  I was trying to make 
sense of that code, and I think now that I didn't fully grok things.

I'm tempted to apply the patch unless someone can say why it would break 
things, which would mean that the other functions are broken as well. 
People do use 'use bytes'; we aren't going to remove it any time soon.

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