http://qs321.pair.com?node_id=268616


in reply to Optimizing the bejeezus out of a sub

A number of comments, most of which shouldn't affect performance, but a couple of which might.
  1. Why are you predeclaring $val, $sec, and $v? Move the declaration inline. I doubt that there is any performance difference but it keeps someone (like me) from wondering whether, for instance, $v is global.
  2. Try assigning @_ to $ret, then decrement $ret on skipped sections. Theoretically faster, though probably imperceptibly so.
  3. You could select $fh temporarily rather than printing to it each time.
  4. Why are you writing your own templating engine? I would be inclined to use one of the many ones out there already, several of which have been optimized far more than I would feel like doing it.