You cannot perform a hash search ( ${...}{...} ) without a hash. But you can create an anonymous hash.
my $apples = ${ { @_ } }{apples}; my $oranges = ${ { @_ } }{oranges};
You can also use simplified post-dereference syntax
my $apples = { @_ }->{apples}; my $oranges = { @_ }->{oranges};
That would be very inefficient. You would create a new hash for each parameter. This is why a named hash is commonly used.
my %args = @_; my $apples = $args{apples}; my $oranges = $args{oranges};
An alternative, however, would be to use a hash fragment.
my ($apples, $oranges) = @{ { @_ } }{qw( apples oranges )};
The following is the post-derefence version, but it is only available in 5.24+ [1] :
my ($apples, $oranges) = { @_ }->@{qw( apples oranges )};
source share