Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2966 connectés 

  FORUM HardWare.fr
  Programmation
  Perl

  Variables et incrementation => Vous trouvez ca normale ?

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Variables et incrementation => Vous trouvez ca normale ?

n°1432900
Danjer
Posté le 29-08-2006 à 09:59:08  profilanswer
 

Vous trouvez ca normale ? :pt1cable:  
 

Code :
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use diagnostics;
  4. my $i = 'A';
  5. print "$i\n";
  6. $i++;
  7. print "$i\n";
  8. $i--;
  9. print "$i\n";


 

$  /tmp/test.pl  
A
B
-1
$ perl -v
This is perl, v5.8.8 built for i486-linux-gnu-thread-multi
 
Copyright 1987-2006, Larry Wall
 
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
 
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
 


 
Ce que je comprends pas c'est que j'ai deja utilise ca il y a longtemps. J'ai pas trouve de vieille version de Perl pour faire ce test.


---------------
Cdl, Danjer
mood
Publicité
Posté le 29-08-2006 à 09:59:08  profilanswer
 

n°1432913
franceso
Posté le 29-08-2006 à 10:11:47  profilanswer
 

effectivement, c'est plutôt étonnant...
 
même résultat chez moi (normal puisque ma version est pas beaucoup plus vieille que la tienne)


---------------
TriScale innov
n°1432940
anapajari
s/travail/glanding on hfr/gs;
Posté le 29-08-2006 à 10:52:34  profilanswer
 

non c'est pas étonnant, c'est marqué dans la doc :o

Citation :


Auto-increment and Auto-decrement
 
``++'' and ``--'' work as in C. That is, if placed before a variable, they increment or decrement the variable before returning the value, and if placed after, increment or decrement the variable after returning the value.
 
The auto-increment operator has a little extra builtin magic to it. If you increment a variable that is numeric, or that has ever been used in a numeric context, you get a normal increment. If, however, the variable has been used in only string contexts since it was set, and has a value that is not the empty string and matches the pattern /^[a-zA-Z]*[0-9]*$/, the increment is done as a string, preserving each character within its range, with carry:
 
    print ++($foo = '99');      # prints '100'
    print ++($foo = 'a0');      # prints 'a1'
    print ++($foo = 'Az');      # prints 'Ba'
    print ++($foo = 'zz');      # prints 'aaa'
 
The auto-decrement operator is not magical.


n°1432970
Danjer
Posté le 29-08-2006 à 11:28:12  profilanswer
 

anapajari a écrit :

non c'est pas étonnant, c'est marqué dans la doc :o
 
The auto-decrement operator is not magical. [/quote]


Effectivement... je perds la memoire. J'aime bien la precision dans la 3eme edition d'oreilly :

Citation :


The autodecrement operator, however, is not magical, and we have no plans to make it so.


---------------
Cdl, Danjer
n°1433149
franceso
Posté le 29-08-2006 à 16:10:13  profilanswer
 

merci pour la précision : je ne connaissais pas ce détail... :jap:


---------------
TriScale innov

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Perl

  Variables et incrementation => Vous trouvez ca normale ?

 

Sujets relatifs
variables d'environnements??Modifier les valeurs des variables passées en get
[Résolu] Bug embêtant avec les variables de session[PHP] question simple sur les variables
Pb de passage de variables de sessionIncrementation dans mysql
Variables IPBincrémentation
[C# .net] Reporting Services + variables à remplirProblème avec les variables get
Plus de sujets relatifs à : Variables et incrementation => Vous trouvez ca normale ?


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR