Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: useful depth of sub routines

by moritz (Cardinal)
on May 27, 2013 at 19:30 UTC ( #1035456=note: print w/replies, xml ) Need Help??

in reply to useful depth of sub routines

As a small data point, I've been programming in Perl for more than ten years, and I've never run into perl's call depth limitation, unless it was code that extensively used recursion. But "normal" code where one method or sub calls another simply doesn't hit that limit.

Some gotchas you might encounter:

  • Calling subroutines that use eval or system functions can reset your $@ and $! variables, so check them right after the place where an error might have occurred.
  • each and regex matching with /g attach (more or less) hidden state to the variables they operate on. Be careful not to leak those variables to subroutines you call. (And be careful not exit a while (my ($key, $value) = each %hash) { ... loop with last or return or die when there's a chance it could be re-entered with the same variable; best avoid it altogether, and iterate over keys %hash in the first place).
  • File handles like IN are global; avoid them in favor of lexical file handles.
  • Avoid function prototypes unless you know exactly what they are doing.
  • die on errors.
  • If you pass a large number of similar argument to a bunch of functions, investigate if it might make sense to turn those arguments (or a subset thereof) into an object, and the functions into method.
  • Although you can inspect the outer context of a function with wantarray and caller, it is usually a bad idea, because it makes code less composable.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1035456]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2018-05-27 08:29 GMT
Find Nodes?
    Voting Booth?