Question 1:
In general, I would think it is better to do this:
my($foo); for ($i = 0; $i < $a_huge_value; $i++) { $foo = getValue(); codeThatUsesFoo($foo); }
Than this:
for ($i = 0; $i < $a_huge_value; $i++) { my $foo = getValue(); codeThatUsesFoo($foo); }
Because in the first case you're reusing the same memory space over and over, and in the second you're creating memory space in every iteration.
True, or not so much? I'm just looking for a standard practice kind of thing here.
Question 2:
Is there a way to do this:
Without creating locally-scoped copies of $key, and $value? In other words, I'm using "my" here to create the anonymous array, but I'm ending up recreating locally-scoped $key and $value at the same time, which I'd rather not do for the reasons outlined in question 1. Other than making the array named rather than anonymous, is there something I'm missing?my($key); my($value); for ($i = 0; $i < $a_whole_lot; $i++) { my($key, $value) = returnsAnArray(); }
Apologies all around for these beginner questions.
CT
In reply to Two Questions on "my" by C_T
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |