Can I link to links without declaring a variable?

I have this code that works

my @new = keys %h1; my @old = keys %h2; function(\@new, \@old); 

but can this be done without declaring the variables first?

function must have its arguments as links.

+6
source share
2 answers
 use strict; use Data::Dumper; my %test = (key1 => "value",key2 => "value2"); my %test2 = (key3 => "value3",key4 => "value4"); test_sub([keys %test], [keys %test2]); sub test_sub{ my $ref_arr = shift; my $ref_arr2 = shift; print Dumper($ref_arr); print Dumper($ref_arr2); } 

Conclusion:

 $VAR1 = [ 'key2', 'key1' ]; $VAR1 = [ 'key4', 'key3' ]; 
+7
source
 function([ keys %h1 ], [ keys %h2 ]); 

From perldoc perlref :

A reference to an anonymous array can be created using square brackets:

$ arrayref = [1, 2, ['a', 'b', 'c']];

+6
source

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


All Articles