Alan M. Carroll <> wrote:
> I went netsearching for this but couldn't find anything in all the
> noise. 
> 
> 1) What is the runtime cost of the scalar operator? Is it constant or
> does it depend on the size of the array? Is it different than
> $#array?  

Evaluating an array in a scalar context returns the size of the array,
$#array returns the index of the last element. So, not the same.

As for the cost, why does it matter if your code is fast enough?
Seriously, it might help answer your question if we knew what problem
you are actually trying to solve.

> 
> 2) What's the best way to turn the result of the map function into an
> array reference? Say one has an array of objects and one wants an
> array reference to an array of object IDs. Should I do A) my @ids =
> map $_->id, @objs; my $ref = [EMAIL PROTECTED];  
> B) my $ref = [ map $_->id, @objs ];
> C) my $ref = \map $_->id, @objs;

B does the pretty much same as A, but without the temporary variable.
The 'best' is the one that expresses your intention most clearly.

C doesn't do what you want, so it gets disqualified from the contest and
retires to the changing rooms in shame for an early shower. Did you try
it, BTW?

> 
> 3) Does the answer to (2) depend on which list generating function is
> called? 

I wouldn't have thought so.

HTH

-- 
Brian Raven 

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to