1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| #!/usr/bin/perl
use warnings;
use strict;
use utf8;
use File::Spec; # Gestion des noms des chemins sous tous les OS
use Config::Std; # Lecture/ecriture d'un fichier .ini
use English '-no_match_vars'; # Importer des variables prédéfinies
my $RepBase = 'E:/_DEV/_Essais';
my $FichierIni = File::Spec->catfile( $RepBase, 'Env.ini' );
my %Config;
if ( -e $FichierIni ) {
read_config $FichierIni => %Config;
}
else {
%Config = (
'GLOBAL' => {
Debug => 'OUI',
},
'fr-FR' => {
Lib_1 => '',
},
'fr-FR' => {
Lib_1 => '',
},
);
}
ActiverAccents();
my $Lang = (var_exist('LANG'));
if ( $Config{GLOBAL}{Debug} eq 'OUI' ) {
print "\nLANGUES CONNUES $Config{GLOBAL}{Langues}\n";
print "Variable environnement Langue = $Lang\n\n";
}
#####################
# Programme principal
print "Lib_1=$Config{$Lang}{Lib_1}\n";
print "Lib_2=$Config{$Lang}{Lib_2}\n";
print "Lib_3=$Config{$Lang}{Lib_3}\n";
###########
# Fonctions
sub var_exist {
my ( $varenv ) = @_;
if ( ! defined $Config{$ENV{$varenv}}{Active}) {
print "\nLangue gérées = $Config{GLOBAL}{Langues}\n";
print "Langue $ENV{$varenv} inconnue\n\n";
exit;
}
return ($ENV{$varenv});
}
#==============================================================
# Pour avoir les accents sur la console DOS
# http://perl.developpez.com/faq/perl/?page=Terminal#AccentsDOS
#==============================================================
sub ActiverAccents {
my $encodage;
# Windows
if ( lc($^O ) eq 'mswin32') {
eval {
my ($codepage) = ( `chcp` =~ m/:\s+(\d+)/ );
$encodage = "cp$codepage";
foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
binmode $h, ":encoding($encodage)";
}
};
}
else {
$encodage = `locale charmap`;
eval {
foreach my $h ( \*STDOUT, \*STDERR, \*STDIN, ) {
binmode $h, ":encoding($encodage)";
}
};
}
return $encodage;
}
#Sinon :
#ü \x81 à \x85 è \x8A
#é \x82 ç \x87 ï \x8B
#â \x83 ê \x88 î \x8C
#ä \x84 ë \x89 |
Partager