in reply to UTF8 - ucfirst() is not working with foreign characters

I was able to test on 5.8.7 (an old freebsd box), as well as 5.10.1 (linux) and 5.12.3 (macosx), and all three behaved the same -- including a problem in the output from Test::More::is() (I don't know why unicode characters get converted to "?").

Here's my "util.pm":

use strict; package util; sub beautify { my ($in) = @_; my $tmp; foreach (split(/\s/o, lc($in))){ $tmp .= ucfirst($_); $tmp .= ' '; } $tmp =~ s/\s$//; return($tmp); } 1;
Here's my test code:
use utf8; use util; use Test::More tests => 4; is( &util::beautify( "àisTheWord"), "Àistheword", "àisTheWord - specia +l character changes case." ); is( &util::beautify( "ùisTheWord"), "Ùistheword", "ùisTheWord - specia +l character changes case." ); is( &util::beautify( "üisTheWord"), "Üistheword", "üisTheWord - specia +l character changes case." ); is( &util::beautify( "ÿisTheWord"), "Ÿistheword", "ÿisTheWord - specia +l character changes case." ); print util::beautify( "ÿisTheWord") . "\n";
And here's the output I got on all three versions:
1..4 ok 1 - ?isTheWord - special character changes case. ok 2 - ?isTheWord - special character changes case. ok 3 - ?isTheWord - special character changes case. ok 4 - ?isTheWord - special character changes case. Ÿistheword
(I put in that last print statement just to check that it would correctly show what was expected on a utf8-capable terminal. I also left out the "u with circumflex because for some reason I couldn't post its upper-case form correctly -- very strange.)

UPDATE: I should add that the command line I used was "perl -C31 test-util.t" (and it seems "-CS" would do the same thing.) Anyway, the tests do pass for me, despite the test message getting munged. So what are you doing that's different?

SECOND UPDATE: I added use Test::More::UTF8 as per mje's suggestion below, and that fixed the output messages -- thanks++!!

Replies are listed 'Best First'.
Re^2: UTF8 - ucfirst() is not working with foreign characters
by mje (Curate) on Jan 11, 2012 at 09:25 UTC