Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Saturday February 16, 2008
04:42 AM

Even/Odd/Prime, etc?

[ #35673 ]

I know it's on the CPAN, I just can't find it yet. I want a module which does something like this:

use Number::Properties ':all';
my @odds   = grep { odd   $_ } @num_list;
my @evens  = grep { even  $_ } @num_list;
my @primes = grep { prime $_ } @num_list;
my @negatives = grep { negative ...

You get the idea.

Is it out there?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I'm of aware of something exactly like that, although I've hacked stuff similar to it over, e.g., Math::Prime::TiedArray [] when playing at Project Euler []. In fact, gathering all those is_(prime|abundant|fibonacci|*) functions under a Number::Class (still trying to find a better name for it) module is something I want to do when I'll have truckloads of round tuits to spend (ah!).

  • perl -MNumber::Properties=prime \
         -MList::MoreUtils=lastval \
         -E '$x = lastval { prime } 2 .. Inf;
             say "the largest prime number is $x"'