My thought on this is that, if the dictates of your application lend or require you to return a list, rather than a ref, try and return the list without building an array first, if it's sensible to do so.
As a example, rather than
sub get_3d_xyz {
$self = shift;
my @xyz = ( $self->get_x()
, $self->get_y()
, $self->get_z() );
return @xyz;
}
save allocating and building the intermediate lexical array and do
sub get_3d_xyz {
$self = shift;
return ( $self->get_x(), $self->get_y(), $self->get_z() );
}
Or even,
use constant SELF => 0;
sub get_3d_xyz {
( $_[SELF]->get_x()
, $_[SELF]->get_y()
, $_[SELF]->get_z() );
}
Each of those steps shaves a few micro/milliseconds of the operation. Not a lot as and of itself, but at the heart of a 3d-graphic class, significant enough.
Updated: Corrected a couple of typos. Thanks ihb.
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.