While looking at Crian's post, I'm having trouble getting the second example to work (the first one works correctly) but the second (the second "f" sub) does not print at all.
Am I doing something wrong, or did I overlook something? I copied & pasted his code directly (changing the second "f" subroutine to a "g" for clarity) but it does not work for me.
This is my first programming language so I don't have any other syntax I can fall back on to make sure I am doing these correctly. Coincedently, as I try to pick up C++, I'm also having problems with references. Are there any other good (beginner) tutorials or books on references that I've overlooked?
Ultimately, I would like to pass a couple of arrays to a subroutine compare them, do some other calculations and return multiple arrays back
Something like this:
my @array1 = (0..9); my @array2 = ('a'..'l'); (@a1, @a2) = &f(\@array1, \@array2); print "\@a1 is: @a1\n"; print "\@a2 is: @a2\n"; sub f { my @a1 = @{shift}; my @a2 = @{shift}; ... return (\@a1, \@a2); }
Thanks
In reply to Help with references by coldmiser
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |