in reply to Modify array elements inside for loops

use local :
local @a = (1 .. 9); # How can I use my here { for my $e (local @a) { $e += 1; } }

UPDATE : This is BAD !
See below why and how to do it properly...

Replies are listed 'Best First'.
Re: Re: Modify array elements inside for loops
by merlyn (Sage) on Mar 06, 2001 at 21:36 UTC
     
    local @a = (1 .. 9);  # How can I use my here 
    { 
       for my $e (local @a) { 
              $e += 1; 
       } 
    } 
    
    Your inner local @a there creates a new @a with an empty list. Add a print $e inside to see that.

    See the other answers in this thread for more correct answers.

    -- Randal L. Schwartz, Perl hacker

      Oops ! You're right I feel so ashamed...
      :-(

      of course
      for my $e (local @a=@a) {
      is too ugly to be used, mirod did it the right way anyway...

      UPDATE : Mirod, arturo, and you (merlyn) did it the right wayS (TIMTOWTDI)
      I still wonder how I managed to get a so poor solution with so many good ways laying in front of me.
      (Who said half-brained ?!?)