Problème avec condition if

Résolu/Fermé
ayrton16 Messages postés 14 Date d'inscription mardi 14 janvier 2003 Statut Membre Dernière intervention 29 octobre 2015 - 23 mai 2014 à 10:43
ayrton16 Messages postés 14 Date d'inscription mardi 14 janvier 2003 Statut Membre Dernière intervention 29 octobre 2015 - 23 mai 2014 à 17:01
Je n'ai jamais programmé en Perl, mais je dois écrire une instruction simple qui pourtant me pose problème...

Cela consiste à récupérer une variable (à partir d'un URL).
Si la variable "lang" = fr on assigne une certaine valeur à la variable BT-ACCUEIL
et si la variable "lang" = nl on assigne une autre valeur à la variable BT-ACCUEIL

Voici mon script :

----------------------------------------------------
my $reqLang=new CGI;

$varLang=$reqLang->param("lang");
$fr="fr";
$nl="nl";

if($varLang==$nl){
$BT_ACCUEIL="bt_accueil-nl.png";
}
elsif($varLang==$fr){
$BT_ACCUEIL="bt_accueil-fr.png";
}

print"$varLang\n";
print"$BT_ACCUEIL\n";
------------------------------------------------------

En testant, je vois que le paramètre "lang" est bien récupéré et bien stocké dans $varLang..
Mais $BT_ACCUEIL garde toujours la valeur du premier if....

Quelque chose m'échappe, auriez vous une solution?

2 réponses

dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
23 mai 2014 à 14:45
hello
remplacer == par eq puisque ce sont des chaines de caractères.
1
dubcek Messages postés 18718 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 22 mars 2024 5 615
23 mai 2014 à 16:29
avec use warnings; il se plaint des ==
0
ayrton16 Messages postés 14 Date d'inscription mardi 14 janvier 2003 Statut Membre Dernière intervention 29 octobre 2015 5
23 mai 2014 à 17:01
Hello,

yes ça marche :-)

Merci!
0