Archive for the ‘ Perl ’ Category

Using translation tools: babelfish / google / yahoo

Languages: Chinese-simp, Chinese-trad, Dutch, English, French, German, Greek, Italian, Japanese, Korean, Portuguese, Russian, Spanish

Requirements:

IO::String
WWW::Babelfish
#!/usr/bin/perl
 use strict;
 use warnings;
 use WWW::Babelfish;
 
 # text to translate
 my $text_source = 'I like to test this service.';
 
 # create the Babelfish service
 my $service = WWW::Babelfish->new(
     service => 'Babelfish',
 );
 
 # check for errors
 if (not defined $service) {
     die "Babelfish server unavailable";
 }
 
 # show text to be translated
 print "[EN] $text_source\n";
 
 # translate to Italian
 my $text_target = $service->translate(
     source          => 'English',   # source language
     destination     => 'Italian',   # destination language
     text            => $text_source,    # text to translate
 );
 if (not defined $text_target) {
     print "Error while translating to Italian";
 }
 else {
     print "[FR] $text_target\n";
 }

Install perl modules via CPAN (command line)

* Check if module is installed. Errors mean missing module.

      $> perl -MModule::Name -e 1

* See documentation of the module if installed.

      $> perldoc Module::Name

* Open CPAN shell:

      $> perl -MCPAN -e shell

* To reconfigure the shell if needed.

      cpan> o conf init

* Install an available module.

      cpan> install Module::Name

* Force install if test fails.

      cpan> force install Module::Name

* To manual install perl modules.

      $> perl Makefile.PL
      $> make
      $> make test
      $> make install

If there are some missing libraries (ex. libmysqlclient.so )

      export LD_LIBRARY_PATH=/usr/local/mysql/lib/

First steps

#!/usr/bin/perl
 
#use chilkat;
 
$ftp_inn = "/home/jorn/ftp/";
$ftp_out = "/var/www/orange_checkout/ftp/";
 
 
 
 
chdir $ftp_inn;
 
 
 
$dir_lookup = qx(ls *.zip);
 
$i = 1;
foreach $item (split(/\n/,$dir_lookup)) {
    print $i." => \n".$item."\n";
 
    # Extraire le nom du repertoire ( moins '-xy~.zip') 
    $_ = $item;
    s/((-)[a-z]*(.zip))|(.zip)//gi;
    print "$_\n";
    $dir_name = $_;
 
    # Lire la date ( moins saute de ligne )
    $date = qx(date +'%Y%m%d%H%M%S');
    $_ = $date;
    s/\n$//gi;
    $dir_name .= '_'.$_;
 
    # Creer le repertoir 
    mkdir $ftp_out.$dir_name;
 
    # Unzip le zip dans le bonne reperoire
    $unzipped = qx(unzip $item -d $ftp_out$dir_name);
    print $unzipped."\n";
    $i++;
 
    # Construction du string pour appeller le orftphandler.php
    $appel_php = '';
}
 
 
 
 
 
 
 
 
#print "\n".substr($item,0,length($item)-4)."\n";
 
 
#$phrase = 'l1233eg.rbeen-lepommeTYeLee-beta.zip';
#$_ = $phrase;
#$cheche = /(zip)/;
#s/(-)[a-z]*(.zip)//gi;
#print "$_\n";
#print $phrase."\n";
 
 
 
#print while <STDIN>;
#print "Hello $_!\n" foreach qw(world Dolly nurse);