in reply to Re^2: More efficient dereferencing of a subroutine return
in thread More efficient dereferencing of a subroutine return
To dereference an array reference returned from a subroutine, you can use:
my @array = @{ sub_returning_aref() };
To get the actual reference, no dereferencing is needed:
my $aref = sub_returning_aref();
On the other hand, if a subroutine returns a list, you can assign it directly to an array:
my @array = sub_returning_list();
To create an array reference, you need to create an anonymous array, as the subroutine returns a list, not an array.
my $aref = [ sub_returning_list() ];
There's nothing special about keys.
my @array = keys %hash; my $aref = [ keys %hash ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: More efficient dereferencing of a subroutine return
by mrbark (Acolyte) on Apr 12, 2021 at 13:39 UTC |