How can I assign the result of calling a routine to array references in Perl?

Is it possible to assign an array variable to reference an array instead of scalar variables?

Instead of this:

($a, $b) = some_sub(\@d, \@e);

I need something like this:

(@x, @y) = some_sub(\@x1, \@y1);

If so, how can I dereference it. As with the previous one, @$xxxxfor us.

Thanks.

+3
source share
2 answers

You can do this in 2 steps (actually 3 lines):

my ($x_ref, $y_ref) = some_sub(\@x1, \@y1);
my @x = @{ $x_ref };
my @y = @{ $y_ref };

The question is: wasn’t it easier to just omit direct arrays and start using links everywhere?

+7
source

( ), , , . , " ". push , . .

. , , ?

my @array = @{ some_sub() };

, , Axeman , . , , Depesz suggestion - , .

perldoc perlreftut Perl. perldoc perllol perldoc perldsc.

, , ?

+4

Source: https://habr.com/ru/post/1719500/


All Articles