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

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://661577]
[LanX]: oh you want the result line by line?
[jdporter]: ok, LanX, then what?
[jdporter]: It doesn't have to be line by line. Just "my program" "writes" to the external prog and also/then "reads" from it.
LanX open (You are not allowed to open to a command that pipes both in and out, but see IPC::Open2, IPC::Open3, and Bidirectional Communication with Another Process in perlipc for alternatives.)
[jdporter]: IPC::Open2, I guess
[jdporter]: yes, that
[pryrt]: 1nickt: academically, perl -MDevel::Peek -lE 'Dump(42); Dump(42.0)'

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (12)
As of 2017-05-24 20:33 GMT
Find Nodes?
    Voting Booth?