⭐ in reply to Is it possible to do pass by reference in Perl?
In fact, passing by reference is a must to preserve the values in separate data structures, even an array and scalar. For instance:
will print:my @array = qw ( 1 2 3 4 5 ); my $num = 6; &testsub ( @array, $num ); sub testsub { my ( @list, $single ) = @_; print @list; }
Passing those values via the @_ flattens all values into one long list. However:123456
will print:my @array = qw ( 1 2 3 4 5 ); my $num = 6; &testsub ( \@array, $num ); sub testsub { my ( $list, $single ) = @_; print @$list; }
where passing the array by ref will keep the values from all merging into the single list.12345
|
---|
In Section
Seekers of Perl Wisdom