Gael Pegliasco wrote:
>
>Yes, this is true, but the natural syntax, for me, to manipulate sets,
>is the one of arrays.
>
>It is not natural to write :
>
>%my_fruit_set = ( 1 => 'orange', 2 => 'lemon' );
>
>but it is natural to write :
>
>@my_fruit_set = ( 'orange', 'lemon' );
>
>I don't want to have to deal with keys of hashes because my set elements
>don't care about them !


Adjust your thinking a bit, not the language. Try:

    %my_fruit_set = (orange => 1, lemon => 1);
or
    @my_fruit_set{qw/orange lemon/} = ();

Then you can query:

    if (exists $my_fruit_set{orange})       # Is "orange" in the set?
    delete $my_fruit_set{lemon}             # Remove "lemon" member
    @my_fruit_set{keys %his_fruits} = ();   # Add members from another set

Hashes are random access -- like sets. Arrays are linear access.
Not like sets.
    
I suggest you find a copy of _Mastering Algoritms with Perl_,
by Orwant, Hietaniemi, and Macdonald, published by O'Reilly.
It has a good introductory chapter on how to represent sets
with perl hashes. It contains code -- most of it quite simple
and short -- for implementing union, intersection,  complement,
etc, with hashes and with bit vectors.

Also, as TomC recommended, do check out the existing modules
on CPAN. 

 ----------------------------------------------------------------------
 Eric J. Roode,  [EMAIL PROTECTED]           print  scalar  reverse  sort
 Senior Software Engineer                'tona ', 'reh', 'ekca', 'lre',
 Myxa Corporation                        '.r', 'h ', 'uj', 'p ', 'ts';

Reply via email to