Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: struggling with sub-routines

by arturo (Vicar)
on Jun 18, 2002 at 13:51 UTC ( [id://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.

hth

I mistrust all systematizers and avoid them. The will to a system shows a lack of integrity -- F. Nietzsche

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-23 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found