in reply to Re^2: More efficient dereferencing of a subroutine return
in thread More efficient dereferencing of a subroutine return

You say "dereferencing", but at the same time "$arrayref". That's confusing.

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 ];

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

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
    Ah! Indeed... I must still be asleep... :) I meant referencing, not DEreferencing, so [ keys %hash ] is what I was looking for. Thank you!