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


in reply to Returning lists vs arrays

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.