--- David Draley <[EMAIL PROTECTED]> wrote:
> What would be the best way to add only the even array elements?
>
> @array[0..9];
>
> #result of even elements
>
> thank you
David,
Just don't do:
use strict;
my @data = qw/ 1 2 3 4 5 9 /;
my $sum = 0;
map { $sum += $data[$_] if $_%2 } ( 1..$#data );
print $sum;
Had to toss that out there for fun, but the "map in void context" police would jump on
me if I
seriously suggested it :)
Cheers,
Curtis "Ovid" Poe
PS Side note: I have a date tonight with a rather interesting lady. I can only
imagine that if
she realizes that I find diversions such as the above map statement amusing, she's
going to run
screaming for the hills (and join all of my other exes out there, no doubt :).
=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/
__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]