in reply to Pushing Arrays into Hash without nesting
Hi,
At the top of your script you have
... and then in the sub in question you have effectivelymy @array = (10 .. 12); $source{'data'} = \@array;
$data = 'data'; # via arg my @array = $source{$data} ; return @array;
First of all, why attempt to pass the array as a list? In general it's better to pass references around, like the one you stored in the hash. Just return the reference, and let the caller dereference and handle the list. You can dereference the result of the subroutine call, like this:
push (@{ $hash{foo}{bar} }, @{ addSomeNumbersFromSource("data") });
Hope this helps!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Pushing Arrays into Hash without nesting (updated)
by AnomalousMonk (Archbishop) on Feb 13, 2021 at 23:51 UTC | |
by 1nickt (Canon) on Feb 14, 2021 at 00:07 UTC |