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 surce | Comments |
- #!/usr/bin/perl
- #use warnings;
- print
"\n"."="x79;
- print "\nMiniprogram:
Zawgyi test program (Zawgyi 1.01)";
- print
"\n"."="x79;
- print "\n\nDIR WITH
BURMESE (eg. country/burma): ";
- $dir =
<STDIN>;
- chomp($dir);
- opendir(DIR, $dir) or
die "Cannot open dir: $dir";
-
- print "\nSAVE THE
RESULTS INTO A FILE? (Y/N): ";
- $save =
<STDIN>;
- chomp($save);
- if ($save eq "y" or
$save eq "Y" ) {
-
print "\nRESULTS INTO (eg. local/export.txt): ";
-
$export = <STDIN>;
-
chomp($export);
-
open(INFO,">:utf8",$export) or die "Cannot open file
$export.";
-
print INFO "="x50;
-
print INFO "\nTESTING FOR ZAWGYI IN: \n$dir";
-
print INFO "\n"."="x50;
-
print INFO "\n"."-"x50;
-
print INFO "\nFILE\tZAWGYI (NO/YES)";
-
print INFO "\n"."-"x50;
- }
- print
"\n"."-"x79;
- print "\nFILE\tZAWGYI
(NO/YES)";
- print "\n"."-"x79;
- while (my $file =
readdir(DIR)) { #open directory
-
next unless ($file =~ m/\.txt$/); #open each file.txt
-
open(INPUT,"<:utf8",$dir."/".$file) or die "Cannot open
file $file.";
-
my $f=0;
-
while(<INPUT>) {
-
chomp($_);
-
if ($f == 0){
-
if ($_ =~/[\x{105A}-\x{1097}]/) {
-
if ($save eq "y" or $save eq "Y" ) {
-
print INFO "\n$file\tYES";
-
}
-
print "\n$file\tYES";
-
$f=1;
-
}
-
}
-
}
- if
($f == 0) {
-
if ($save eq "y" or $save eq "Y" ) {
-
print INFO "\n$file\tNO";
-
}
-
print "\n$file\tNO";
-
}
-
close INPUT;
-
}
- closedir DIR;
- close INFO;
- print
"\n"."-"x79;
- print "\n\n";
-
- if ($save eq "y" or
$save eq "Y" ) {
- print "FILE
EXPORTED\n";
- }
- print "DONE (press ENTER
to close)\n";
- <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.
|