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

  • Comment on Re^8: Begginer's question: If loops one after the other. Is that code correct?
  • Download Code

Replies are listed 'Best First'.
Re^9: Begginer's question: If loops one after the other. Is that code correct?
by predrag (Scribe) on Jan 14, 2017 at 17:01 UTC

    Hauke D, I simply can't say enough thanks to you. I can only hope that all this is useful to you too and maybe it is true, because as I know, in pedagogy they say the best way for learning is to teach someone (people) and the inverse: teaching is considered as the best way for learning.

    I've already had installed cpanm, and with its help, I've succesfully and easy instaled these two modules you used in the code. They are really powerful, and of course, I constantly convince myself how CPAN is huge and powerful

    Just tried your code and it works, completely well. Excellent. I see the code does two things, and I have to look at that more detailed and make many tests. I am really excited and happy but you should remember that I am still a beginner and need a time to settle knowledge acquired here

    It is fantastic you showed me into IDN encoding. As I've wrote last time, I've recently learned something about IDN and got ACE string on my Cyrillic domain on our national domain service web page form, so I will try to check it with your script now. So happy!

    You mentioned "ISO/R 9" and it is my shame, at this moment I can't tell you if it is what I use. It seems I am a bit more confused and a bit tired today that can't answer now. Anyway, you brought me to the solution of so important things for my project

    Websites with Cyrillic domain name are rare and I've noticed on the web that these mostly have the rest on the url on Latin, but it seems I will have in Cyrillic, wow!

      Hi predrag,

      I can only hope that all this is useful to you too and maybe it is true ... teaching is considered as the best way for learning.

      Yes, part of the reason I wrote the code above is to satisfy my own curiosity :-)

      I've already had installed cpanm, and with its help, I've succesfully and easy instaled these two modules you used in the code.

      I just wanted to point out that since CPAN is huge, there are also a lot of modules that might not be well-tested or have other problems. In this node I wrote about some ways to tell which modules are good and which might not be.

      Also, another thing is that it's usually recommended to avoid modifying the Perl that comes with your Linux system. The system Perl is usually managed by the system's package manager, and there might be programs that require those specific versions of Perl or its modules. Also, installing Perl modules into the system Perl with both the package manager and CPAN can sometimes lead to breaking the installation. If you've already installed modules into your system Perl, then as long as your system keeps running normally you don't need to worry, but I would recommend installing a separate version of Perl locally so that you can avoid touching the system Perl at all when installing modules. Another advantage of installing a separate version of Perl is that you can always have the latest version. The program perlbrew makes this very easy.

      Regards,
      -- Hauke D

        Hi Hauke D,

        I've partially changed the title of this node but am not sure if that is ok? Probably I had to change it once before, when new question about converting to Cyrillic appeared but I wasn't sure if I could do that the right way. I wonder if it is possible to do now and if yes, should I do that?

        Thanks for the links. I would like to learn CGI scripting later this year and it is very useful for me to know that CGI module is not more recommended.

        I will have in mind the possibility to have separate Perl installations. Then, in scripts, I should address the version I want to use?

        Two days ago, I've installed the old Ubuntu version (12.04) on my Virtual Box and there is a little higher Perl version then I have on other systems. I was surprised with so many Perl modules in Ubuntu Software Center and suppose just a part are CPAN but others are not. So, I've installed several through this Center and just few through CPAN. Then later, I've read in your post about recommendation to avoid modifying the Perl in the system and about installing modules two ways.

        I think my systems work well till now, but will have in mind the warning.

        Among other modules, I've installed Chart::Clicker (not sure now but probably with cpanminus) because found on the web that it is a simple yet powerful tool for plotting graphs etc. It was very surprising to see that it resulted in 102 distributions installed! The examples for that module work very well and graphs are really nice but I would have a question: ok, for a desktop computer the number of these modules is maybe not important but for the server, is it recommended to have just that so demanding module or work with some others?

        At the and, I would also ask You, if it is ok to sometimes send You a personal message, when I am not sure whether my reply to your post is interesting to others or not?

      I've just tried your code for my Cyrillic domain name and ACE string I've already got, works perfectly

        Looked at the web and found a website where is stated Lingua::Translit credits are also given to "Perl community" and among others: Thanks to Dusan Vuckovic for contributing the "ISO/R 9" transliteration table

        It is Serbian name and family name, so it seems ISO/R 9 is what should be used for Serbian. I've seen ISO 9 is also reversible.