Optimizing code

From Dreamwidth Notes
Revision as of 17:52, 6 July 2009 by Sophira (Talk | contribs)

Jump to: navigation, search

This is a page on code optimization--practices that encourage efficient code.

Avoid shift

The shift() function, used to take the first argument from the @_ list, is slow. Instead:

  • For short functions (1-5 lines), use $_[0] for the first argument, $_[1] for the second, etc.
  • For longer functions, use the following construct to assign the values to named scalars:
my ( $foo, $bar ) = @_;

(source)