Issa Mbodji wrote:
> Hello:
>
> I have the following array:
>
> @numbers = qw(1..30);
> How do I go about getting the odd and even numbers and
> store them into 2 different arrays(@odd_numb and
> @even_numb).
I don't know any really simple way:
my (@odds, @evens);
foreach (1 .. 31) {
if ($_ & 1) { push @odds, $_; } else { push @evens, $_; }
}
or using map (which just muddles it up more even though it's a bit shorter):
my (@odds, @evens);
map { if ($_ & 1) { push @odds, $_; } else { push @evens, $_; } } (1 .. 31);
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (Free site for Perl/Lakers)
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs