in reply to Re^7: Begginer's question: If loops one after the other. Is that code correct?
in thread Begginer's question: If loops one after the other. Is that code correct?
Hi predrag,
One separate task for my site in Cyrillic will be IDN encoding
I just wanted to point out the power of CPAN. Perl and CPAN have been around for a long time and two of several areas where Perl excels is text processing and web development. I've already linked you to several HTML and XML processing modules, and a quick search on CPAN for "translit" is what gave me, among other things, Lingua::Translit, and a quick search for "IDN" shows me Net::IDN::Encode, again just one module among several.
use warnings; use strict; use open qw/:std :utf8/; use Lingua::Translit; my $tr = new Lingua::Translit("ISO/R 9"); my $txt = "\x{0441}\x{0440}\x{043F}\x{0441}\x{043A}\x{0438}"; my $latin = $tr->translit($txt); my $cyrillic = $tr->translit_reverse($latin); die "text mismatch" unless $txt eq $cyrillic; print "$latin <-> $cyrillic\n"; use Net::IDN::Encode qw/domain_to_ascii domain_to_unicode/; my $idn = "\x{0442}\x{0435}\x{0441}\x{0442}.\x{0441}\x{0440}\x{0431}"; my $asc = domain_to_ascii($idn); my $dom = domain_to_unicode("xn--e1aybc.xn--90a3ac"); die "domain mismatch" unless $idn eq $dom; print "$asc <-> $dom\n";
Output:
srpski <-> српски xn--e1aybc.xn--90a3ac <-> тест.срб
Note: I did not verify that the "ISO/R 9" transliteration table is identical to the Serbian / Cyrillic transliteration table you're using, but at least Wikipedia says it's suitable.
Regards,
-- Hauke D
|
|---|