Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Returning lists vs arrays

by BrowserUk (Patriarch)
on Jan 20, 2003 at 17:01 UTC ( [id://228395]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://228395]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-25 06:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found