How to reference the return value of perl sub
Code:
my $compare = List::Compare->new(\@hand, \@new_hand); print_cards("Discarded", $compare->get_Lonly()) if ($verbose); print_cards expects (scalar, array reference).get_Lonly returns an array. What is the syntax for converting this to a link so that I can pass it to print_cards? \@{$compare->getLonly()} does not work, for example.
Thanks!
You probably want
print_cards("Discarded", [$compare->get_Lonly]) Routines do not return arrays; they return a list of values. We can create an array reference using [...] .
Another option would be to create an explicit array
if ($verbose) { my @array = $compare->get_Lonly; print_cards("Discarded", \@array) } The first solution is a shortcut to this.
@{ ... } is the dereference operator. It expects an array reference. This does not work, as you think, if you give him a list.