Here's my "util.pm":
Here's my test code: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;
And here's the output I got on all three versions: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";
(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.)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
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++!!
In reply to Re: UTF8 - ucfirst() is not working with foreign characters
by graff
in thread UTF8 - ucfirst() is not working with foreign characters
by tyatpi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |