You may know this already but...
if you end up doing this as Zaxo suggested, then your
@array better be my()ed in the loop for $i; otherwise, all
elemets of $page_graphic->[$i] will point to the same set
of values (probably not what you want).
You could do
$page_graphic->[$i]->{array} = [@array];
# ... other stuff ...
or
loop_construct {
my @array = @other_array;
$page_graphic->[$i]->{array} = [@array];
# ... other stuff ...
}
Regards. | [reply] [d/l] [select] |
loop_construct {
my @array = @other_array;
$page_graphic->[$i]->{array} = \@array;
# ... other stuff ...
}
Sorry about that. | [reply] [d/l] |
Perhaps this is beating a dead horse, but it appears you've hit upon what cLive ;-) apparently originally meant to do with this.
$page_graphic->[$i]->{array} = [@array];
By specifying the square brackets around @array, assigning a reference to an anonymous array containing copies of the elements of @array.
No need of correction (IMHO), since cLive ;-) didn't give us the full context of his code (i.e., how is @array populated?), although declaring @array with my within the loop and using \ to take a reference to it is a perfectly valid Way To Do It.
Generally, though, taking references to named array and/or hash variables within a loop raises a red flag with me.
dmm
You can give a man a fish and feed him for a day ...
Or, you can teach him to fish and feed him for a lifetime
| [reply] [d/l] [select] |
Y'know, that is a very good point.
It's probably only because every var I used is as localised as possible with 'my' that this has never been a problem - yes, in this has the array is purely local to the sub it's used in, but the $page reference isn't. Most of the other elements referenced are anonymous.
I think I was definitely having too long a session yesterday. What I've done works, but I think I'll rewrite it later when i have a better idea of the general context it will be used in. And, I'll mark the reference of @ array possible issue in the comments in case it manages to creep in (unlikely, but safer :)
Thanks again for an interesting point.
cLive ;-)
| [reply] |