Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: struggling with sub-routines

by arturo (Vicar)
on Jun 18, 2002 at 13:51 UTC ( #175359=note: print w/replies, xml ) Need Help??

in reply to struggling with sub-routines

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:

return $first; return $second; return $third; return $forth; return $others;
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:
return ($first, $second, $third, $forth, $others);

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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://175359]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2023-06-01 13:10 GMT
Find Nodes?
    Voting Booth?

    No recent polls found