in reply to Re^2: Date::Manip and German months names (solved)
in thread Date::Manip and German months names
a proper solution would of course have to dynamically construct the correct character set depending on the language being selected.
A simpler solution might be
foreach $from (keys %{ $Lang{$L}{"Repl"} }) { $to=$Lang{$L}{"Repl"}{$from}; utf8::upgrade($from); # Use Unicode semantics for \b s/\b$from\b/$to/i; }
He's already assuming $from doesn't contains symbols since he's not using quotemeta, so using \b doesn't introduce any limitations.
My solution will also make "MÄR" work, unlike the current implementation and your proposed solution.
Update: Shoot! \w includes digits, so \b won't do. There's a POSIX class that includes just letters that does the trick:
utf8::upgrade($from); # Use Unicode semantics s/(^|[^[:alpha:]])$from($|[^[:alpha:]])/$1$to$2/i;
Update: As discovered below, what needs to be upgraded is the string on which s/// acts.
utf8::upgrade($_); # Use Unicode semantics s/(^|[^[:alpha:]])$from($|[^[:alpha:]])/$1$to$2/i;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Date::Manip and German months names (solved)
by almut (Canon) on Jul 09, 2008 at 23:22 UTC | |
by ikegami (Patriarch) on Jul 10, 2008 at 00:15 UTC | |
by almut (Canon) on Jul 10, 2008 at 00:54 UTC | |
by ikegami (Patriarch) on Jul 10, 2008 at 01:38 UTC |