I have a function in perl that returns a list. I understand that when foo () is assigned a list, it is copied:
sub foo() { return `ping 127.0.0.1` }
my @list = foo();
Then @list
you need to transfer to another list, for example @oldlist = @list;
, and another copy is made. So I was thinking if I could just make a link from the returned list, for example my $listref = \foo();
, and then I can assign this link, but that will not work.
The function I'm working with runs a command that returns a fairly large list (the ping command is for example purposes only), and I call often, so I want to minimize copies if possible. What is a good way to handle this?
source
share