Loading ...
Sorry, an error occurred while loading the content.

use strict; within loop why " my auto-increment " dont increase.

Expand Messages
  • Leon
    Hi Members,My question :- Could members please help me to understand why $b is not incremented within the while loop below.Just a comment :- Originally, I
    Message 1 of 1 , Jan 1, 2002
    • 0 Attachment
      Hi Members,

      My question :- Could members please help me to understand why $b is not
      incremented within the while loop below.

      Just a comment :-
      Originally, I always thought that in using strict, it is mandatory that I
      declare all new variables with a 'my'. Correct me if I am wrong, however now
      I dont think so as this will prevent us from globalising a variable within a
      block, I have to thank Michael R. Wolf for this.

      Thank You.

      use strict;
      while ($a<10){
      $a++;
      my $b++; # why it did not increment?
      print "$a\n";
      print "$b\n";
      };
      print "\$a = $a\n"; # $a = 10 as expected.
      print "\$b = $b\n"; # $b returns undef, I understand this.


      _________________________________________________________
      Do You Yahoo!?
      Get your free @... address at http://mail.yahoo.com
    Your message has been successfully submitted and would be delivered to recipients shortly.