[tpm] ucfirst() and unicode
linux at alteeve.com
Wed Apr 7 12:12:31 PDT 2010
On 10-04-06 03:33 PM, Stuart Watt wrote:
> Digimer wrote:
>> From reading perldoc perlunicode, I was able to figure out why
>> ucfirst() wasn't doing anything; The data I am altering is coming from
>> a UTF8-encoded database. I also see the example of creating UTF8
>> compatible ToUpper(), ToLower(), etc.
>> There isn't an example of a compatible ucfirst() alternative, and as I
>> read it, I'd need to create a custom function listing the
>> source->destination unicodes to convert... This seems tedious so,
>> given that laziness is the source of all code, I am guessing someone
>> has come up with another way. Failing that, is there such a function
>> My CPAN search for 'ucfirst unicode' failed (though it's always
>> possible that there is a PEBCAK).
>> tl;dr - need a ucfirst() variant that works with Unicode strings.
> I think some of this is locale-specific, which is why it isn't obvious.
> i.e., what actually happens can vary from locale to locale. For example,
> é can be uppercased to E and É depending on which region you are in. See
> for some stuff.
> Just putting "use locale;" in your script might be a good place to start.
> All the best
This got me going in the right direction, thank you!
I had already been using 'use locale', but while looking into it I saw
that is plays with what perl interprets \l, \u, \L and \U to mean. From
that, I was able to create this little function that seems to work:
foreach my $char (split//, $word)
E-Mail: linux at alteeve.com
Node Assassin: http://nodeassassin.org
More information about the toronto-pm