i can think of a few ways ...
# loop through the array and check the index
my $index = 1;
for my $value (@array)
{
next if $index%2;
push @only_even , $value;
$index++;
}
# or you can shift two elements and use the last one ...
for my $value (@array) {
# you can also do my ($odd,$even) = splice(@array,0,2);
my $odd = shift @array;
my $even = shift @array;
push @even_only , $even;
}
i did not test the above so use at your own peril ...
On Fri, Sep 07, 2001 at 11:18:22AM +0000, David Draley shaped the electrons to read:
> What would be the best way to add only the even array elements?
>
> @array[0..9];
>
> #result of even elements
>
> thank you
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]