in reply to Match all Odd and Even Numbers
Just contributing a little golf.
my @nums = (0 .. 99); my $odd_even = [ ]; push @{ $odd_even->[$_ & 1] }, $_ for (@nums);
The above actually has been tested. $odd_even->[0] contains a list of even numbers, and $odd_even->[1] contains the odd numbers. You can split them into seperate arrays like this:
my @even = @{ $odd_even->[0] }; my @odd = @{ $odd_even->[1] };
----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
Note: All code is untested, unless otherwise stated
|
|---|