ceedee has asked for the wisdom of the Perl Monks concerning the following question:
I would like to know what happens when I declare a variable within a loop such as my $foo within:
foreach my $a(@bar) { my $foo = &return_something($a); }
I frequently use loops with variables scoped within them and was wondering how expensive this was on memory. Am I better off declaring these variables before the block and undefining them on each iteration?
$foo must be a unique instance in memory on each iteration, how long does each instance stay in memory during this loop?
I would also like to know how to undefine a group of variables at once, other than:
($v1, $v2, $vX) = (0, 0, 0);
Can I undef ($v1, $v2, $vX); or does this only affect the first value in the array? I won't be wanting to refer to these variables outside of these blocks.
Any suggestions?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Loops and my
by mrbbking (Hermit) on May 18, 2002 at 12:56 UTC | |
Re: Loops and my
by TheHobbit (Pilgrim) on May 18, 2002 at 12:36 UTC | |
Re: Loops and my
by ceedee (Sexton) on May 18, 2002 at 13:06 UTC |