L’attractivité de l'économie de la Birmanie

Script supplémentaire en PERL (Télécharcher le script)

Ce petit script test l'encodage d'un fichier pour voir s'il utilise des codes en dehors de la partie du codeblock Myanmar réservée pour la langue birmane. Bien sûr, si le fichier est écrit dans une langue autre du birman le script va penser qu'il s'agit d'un fichier écrit en Zawgyi. Il faudrait donc améliorer le script pour prendre en compte ce problème.


Code surceComments
  1. #!/usr/bin/perl 
  2. #use warnings; 

  3. print "\n"."="x79; 
  4. print "\nMiniprogram: Zawgyi test program (Zawgyi 1.01)"; 
  5. print "\n"."="x79; 

  6. print "\n\nDIR WITH BURMESE (eg. country/burma): ";
  7. $dir = <STDIN>;
  8. chomp($dir); 
  9. opendir(DIR, $dir) or die "Cannot open dir: $dir"; 
  10.  
  11. print "\nSAVE THE RESULTS INTO A FILE? (Y/N): "; 
  12. $save = <STDIN>; 
  13. chomp($save); 

  14. if ($save eq "y" or $save eq "Y" ) { 
  15.       print "\nRESULTS INTO (eg. local/export.txt): "; 
  16.       $export = <STDIN>; 
  17.       chomp($export); 
  18.       open(INFO,">:utf8",$export) or die "Cannot open file $export."; 
  19.       print INFO "="x50; 
  20.       print INFO "\nTESTING FOR ZAWGYI IN: \n$dir"; 
  21.       print INFO "\n"."="x50; 

  22.       print INFO "\n"."-"x50; 
  23.       print INFO "\nFILE\tZAWGYI (NO/YES)"; 
  24.       print INFO "\n"."-"x50; 
  25. }
  26. print "\n"."-"x79; 
  27. print "\nFILE\tZAWGYI (NO/YES)"; 
  28. print "\n"."-"x79;

  29. while (my $file = readdir(DIR)) { #open directory 
  30.        next unless ($file =~ m/\.txt$/); #open each file.txt 

  31.        open(INPUT,"<:utf8",$dir."/".$file) or die "Cannot open file $file."; 
  32.        my $f=0; 

  33.        while(<INPUT>) {    
  34.           chomp($_);        

  35.          if ($f == 0){ 
  36.             if ($_ =~/[\x{105A}-\x{1097}]/) { 
  37.                 if ($save eq "y" or $save eq "Y" ) { 
  38.                   print INFO "\n$file\tYES"; 
  39.                 } 
  40.                 print "\n$file\tYES"; 
  41.                 $f=1; 
  42.                 } 
  43.           } 
  44.        } 

  45.    if ($f == 0) { 
  46.                 if ($save eq "y" or $save eq "Y" ) { 
  47.                   print INFO "\n$file\tNO"; 
  48.                 } 
  49.                 print "\n$file\tNO"; 
  50.        }
  51.       close INPUT; 
  52.     } 

  53. closedir DIR; 
  54. close INFO; 

  55. print "\n"."-"x79; 
  56. print "\n\n"; 
  57.  
  58. if ($save eq "y" or $save eq "Y" ) { 
  59.   print "FILE EXPORTED\n"; 
  60. print "DONE (press ENTER to close)\n"; 
  61. <STDIN>;









8 asking user for name of directory containing burmese files in txt




13 asking user if he would like to save the results or not


17-29 if he would like to save it, he's asked for name of file which will contain the results and some header is printed straight into it.
















34-37 browsing choosen directory and opening every file




40-61 opening every file and looking up for characters used in zawgiy, if it's find, it prints "yes" as zawgii encoding.
































73 ending script by an empty entry (if it's just runned by clicking on a icon (not throught terminal), so user can look up results and it's not closed without his will.