Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: exit calling subroutine

by jbert (Priest)
on Jan 10, 2008 at 09:14 UTC ( #661577=note: print w/ replies, xml ) Need Help??


in reply to exit calling subroutine

Whenever you create a function, whether through initial design or refactoring, you need to give some thought to it's error handling.

Error handling is typically done either via return values (e.g. empty return - gives undef in scalar context or empty list in list context) or by exceptions (with raw eval/die or with a module which provides some syntactic sugar, such as Exception::Class).

There are also bizarre various ways to do this in perl, like the subroutine goto above, or you could stick a loop around the whole thing and call next in the subroutine instead of return. But imho these sorts of things don't aid readability or maintainability - which is the purpose of refactoring in the first place.


Comment on Re: exit calling subroutine
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (12)
As of 2015-07-07 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (92 votes), past polls