in reply to Re: Hash problem
in thread Hash problem
You're right about needing to use a reference to an array for assigning to a hash element, but that way of doing it can be rather wasteful. What you are doing with $Tex{$a} = [@bex] is copying the contents of @bex in to another array and then assign a reference to that new array to $Tex{$a}.
You can avoid the unneccesary copying by just taking a reference to the original array
if (!$Tex{$a}){ $Tex{$a} = \@bex; }
Of course, this only works correctly in a loop if the array you are taking a reference to is scoped to the loop. If not, your method is correct.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Hash problem
by ikegami (Patriarch) on Feb 04, 2006 at 02:12 UTC | |
by BrowserUk (Patriarch) on Feb 04, 2006 at 02:24 UTC |