in reply to Re: Modify array elements inside for loops
in thread Modify array elements inside for loops

 
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

  • Comment on Re: Re: Modify array elements inside for loops

Replies are listed 'Best First'.
Re: Re: Re: Modify array elements inside for loops
by arhuman (Vicar) on Mar 06, 2001 at 21:49 UTC
    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 ?!?)