Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello gr8 ones, Obviously one could roll their own, but are there built-in perl function to handle set theory (via arrays and/or hashes).

What I'm looking for is union, intersection, bisection, etc of arrays or hashes.

thanks, me

Replies are listed 'Best First'.
Re: Set theory in Perl
by broquaint (Abbot) on Apr 15, 2004 at 16:29 UTC
Re: Set theory in Perl
by gjb (Vicar) on Apr 15, 2004 at 16:47 UTC

    Set::Scalar will (most probably) do what you want. Using it you can create sets of scalars (strings, numbers, etc) and perform all the usual set operations on them.

    Hope this helps, -gjb-

Re: Set theory in Perl
by dragonchild (Archbishop) on Apr 15, 2004 at 16:28 UTC
    Have you checked http://search.cpan.org and plugged in "set"? There are no "built-in" functions, but there are tons of modules that can help.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

Re: Set theory in Perl
by mojotoad (Monsignor) on Apr 15, 2004 at 22:16 UTC
    In addition to the ones mentioned above, Set::Infinite is worth mentioning. It's used at the heart of DateTime to calculate events and calendars. And, of course, it can handle infinite sets.

    Matt

Re: Set theory in Perl
by Abigail-II (Bishop) on Apr 15, 2004 at 16:46 UTC
    That's answered in the FAQ.

    Abigail

      Not very well, it's not. Section 4 of the Perl FAQ and the arrays and hashes sections of the Categorized Questions and Answers have some entries on how to perform set-like operations on hashes and arrays. Someone seeking wisdom on how to do "set operations in Perl" could easily miss them.

      jdporter
      The 6th Rule of Perl Club is -- There is no Rule #6.