|Keep It Simple, Stupid|
Re: struggling with sub-routinesby arturo (Vicar)
|on Jun 18, 2002 at 13:51 UTC ( #175359=note: print w/replies, xml )||Need Help??|
The problem you're seeing has to do with the return call; what it does is just that -- returns the value AND stops execution of the subroutine. So, where your sub has:
The only value returned is $first; the rest of those are ignored. What you apparently want to do is return a list, and fortunately, that's easy to do:
or, better yet, since your names clearly suggest an *array*, why not return an array and avoid declaring so many variables?
Your code has a number of other issues (e.g. you pass in a scalar, and yet your subroutine is built to deal with an array, you don't use the return value of your subroutine at all), but I'll just stop here and let others help you out with those issues.
I mistrust all systematizers and avoid them. The will to a system shows a lack of integrity -- F. Nietzsche
In Section Seekers of Perl Wisdom