Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: returns not working

by socketdave (Curate)
on Aug 24, 2005 at 15:35 UTC ( #486239=note: print w/ replies, xml ) Need Help??


in reply to returns not working

I generally don't enclose the return code in parentheses: return 0;

If you aren't, you should use warnings; it may give you a clue to what's going on. You say that return (1) doesn't seem to work. What does it do?


Comment on Re: returns not working
Download Code
Re^2: returns not working
by davido (Archbishop) on Aug 24, 2005 at 15:45 UTC

    The use of parenthesis around the parameter for return has no effect other than possibly to disambiguate the syntax. In other words, return 0; and return(0) will do the same thing.


    Dave

      i think i started doing this out of some vague uneasiness about return handling scalars or lists. now that i think about it, it's pretty much a personal style thing at this point. which do you think is more appropriate?

        From perlsytle:

        Along the same lines, just because you CAN omit parentheses in many places doesn't mean that you ought to:

        return print reverse sort num values %array; return print(reverse(sort num (values(%array))));

        When in doubt, parenthesize. At the very least it will let some poor schmuck bounce on the % key in vi.

        Even if you aren't in doubt, consider the mental welfare of the person who has to maintain the code after you, and who will probably put parentheses in the wrong place.

        My rule of thumb is that if the syntax and meaning are perfectly clear without parenthesis, you can omit them. If leaving them out makes the code confusing, alters the outcome, or impedes readability, better include them.


        Dave

Re^2: returns not working
by Markn (Initiate) on Aug 24, 2005 at 15:56 UTC
    I am using warnings in the main body of the code. if I just use a plain return, it falls out at the return (generally). I am stepping through the code line by line and watching this happen.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2014-08-01 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (13 votes), past polls