Control Flow - Multiple returns or nested conditionalsby JediWizard (Deacon)
|on Oct 07, 2010 at 15:31 UTC||Need Help??|
JediWizard has asked for the wisdom of the Perl Monks concerning the following question:
I have had a difference of opinion with a colleague regarding the use of multiple return statements in a sub routine, as opposed to using nested conditionals. I'd like to hear thoughts from the rest of the community on this topic. Please consider the following subroutines: (all method and variables are fake just to illustrate the example)
Corrected a typo causeing bar to always return 0 for status.
The hash reference being returned could be defined at the beginning for either implementation, to make adding or removing values from it easier, my real question is simply regarding the style of using a return to short circuit the sub routine, and opposed to the nested if/else structures.
Which of these implementations would you prefer and why?
Thank you all in advance for sharing your input. I'm interested to hear what people think
They say that time changes things, but you actually have to change them yourself.