Variables et incrementation => Vous trouvez ca normale ?

Variables et incrementation => Vous trouvez ca normale ? - Perl - Programmation

Marsh Posté le 29-08-2006 à 09:59:08    

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
Reply

Marsh Posté le 29-08-2006 à 09:59:08   

Reply

Marsh Posté le 29-08-2006 à 10:11:47    

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
Reply

Marsh Posté le 29-08-2006 à 10:52:34    

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.


Reply

Marsh Posté le 29-08-2006 à 11:28:12    

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
Reply

Marsh Posté le 29-08-2006 à 16:10:13    

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


---------------
TriScale innov
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed