There is a similar question How can I assign the result of a subroutine call to array references in Perl? but I'm curious about perl's possibilities
Is there a hack in perl to directly dereference element-wise an array of references?
in a code like
sub test { return([1..4],[5..8]); }
my (@a,@b);
my @result = test();
@a = @{$result[0]}; @b = @{$result[1]};
I would like to shorten the code to a simple statement like
sub test { return([1..4],[5..8]); }
my (\@a,\@b) = test();
or in a loop
foreach my $element (\"1",\"2",\"3") {
my $dereferenced_element = $$element;
it would be nice to write something like
foreach my \$element (\"1",\"2",\"3") {
I know that this syntax doesn't make much sense, as I don't want to assign a value to the reference of a variable, but to assign a dereferenced value to the variable itself
but I'm curious if there is anything in that direction in perl's repertoire and I think this example shows the best, what I'm intending to do