in reply to How can I keep the values in the array?

You said something like:
while (my @foo = ...) { ... }
Any variable you declare with my @foo here will disappear at the end of the loop.

Instead, phrase it like:

my @foo; while (@foo = ...) { ... }
If you had use strict; Perl would have complained on your final lines because the variables wouldn't exist at that time.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re: Re: How can I keep the values in the array?
by Limbic~Region (Chancellor) on Mar 03, 2004 at 17:55 UTC
    halley,
    It might also be worth mentioning that just changing the scope of the variable may not lead to the desired results. Each iteration the array is going to get overwritten. If what was desired was the only to remember the first row (as @row1 would indicate) then additional modifications would have to be made such as this.

    Cheers - L~R

Re: Re: How can I keep the values in the array?
by luoina (Acolyte) on Mar 03, 2004 at 18:53 UTC
    Hi thank you for your reply. But I coded the way your show me, the array was still empty after the loop.