in reply to Re: Pushing Arrays into Hash without nesting
in thread Pushing Arrays into Hash without nesting
push (@{ $hash{foo}{bar} }, @{ addSomeNumbersFromSource("data") });
If addSomeNumbersFromSource() is not changed from the
OPed code, then the
return @array;
statement will be evaluated in scalar context (dereferencing a
scalar array reference) and will return the number of
elements in @array.
tybalt89 has it right for the given code:
push (@ { $hash{"foo"}{"bar"} } , @{ (addSomeNumbersFromSource("data"))[0] } );
Update:
Just return the reference, and let the caller dereference and handle the list.Hmmm... On reading 1nickt's reply and re-reading the post to which I was replying, I must admit that that post urged a significant change to the function interface, for which the suggested expression invoking the function was perfectly appropriate. Paying attention to what's written can sometimes be useful. :)
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Pushing Arrays into Hash without nesting
by 1nickt (Canon) on Feb 14, 2021 at 00:07 UTC |