Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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]
[Corion]: Meh. I think I have now the parts down that I want from a simple Javascript frontend for single-page- applications with a aPerl backend. But it seems that all Javascript templating modules either don't support two-way binding (which would be nice) or ...
[Corion]: ... don't support server-side precompilation (which means the client has to compile all templates to Javascript themselves), or are giant frameworks that expect to do everything (which is not what I want)
[Corion]: I feel that there is a talk somewhere in there, either about the structure and parts, or how I used several parts to get a complete whole.
[Corion]: Maybe I can still find something that is compatible with handlebars.js (which has JS precompilation) but allows for two-way data binding (which is great for the UI)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2017-03-30 07:50 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (355 votes). Check out past polls.