On Jul 12, Kurt Edmiston said:
>Coming from C++-land, I've always been taught over and over again that all
>subroutines/functions/blocks/etc should have only a single entry point and
>a single exit point. "It's just good programming practice." But now in
>the world of Perl, I've observed that a "Perl-ish" thing to do is to place
>multiple return/exit/etc statements in certain blocks of code or in
>conditional blocks. (Then again, maybe it isn't Perl-ish, but I've had to
>sort through many perl scripts like this.)
I think one feeling for the C/C++ ideology is that functions are declared
as such:
RTYPE name (TYPE1 ARG1, TYPE2 ARG2, ...) {
/* ... */
return SOMETHING_OF_RTYPE;
}
With Perl, a function might return different things -- a scalar, an array,
a hash, a code reference, etc. It makes sense to have multiple exit
points for different return strategies.
>Also, I was wondering if exiting prematurely like this from a program has
>any adverse affects on the execution of the program.
How is it premature? When a function returns, it returns. What makes a
return at the top of a function any more "premature" than a return at the
bottom?
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **