Thank you for your reply.  I believe your system works
for lists.  For hashes, things get complicated because
equal hashes may serialize with their keys in
different orders using Data::Dumper or Storable. 
FreezeThaw seems to work, though.

So, only Map::Set and Map::Bag now seem relevant, as
they consider order to be irrelevant, and such
behavior is not available from any of the packages
mentioned so far.  In the case of Map::Set, duplicates
are also considered to be irrelevant.  If anyone
thinks these two modules would be useful let me know. 
Otherwise I will not bother posting these to CPAN.

--- END OF RELEVANT DISCUSSION ---

If you're extra curious...

I ran the following code and found that, in my runs,
it always died on the very first iteration:

    #!/usr/bin/perl

    use Data::Dumper;

    for(my $i = 0; $i < 100; $i++) {
        my @list = map {
            chr(rand(254)+1)
        } (0..int(rand(100)));
        my %hash1 = map { $_ => 1 } @list;
        my %hash2 = map { $_ => 1 } reverse @list;

        my $serialized1 = Dumper(\%hash1);
        my $serialized2 = Dumper(\%hash2);

        die $i unless($serialized1 eq $serialized2);
    }

Printing out $serialized1 and $serialized2 showed that
they were unequal strings which represented equal
hashes.

Using Storable::freeze on \%hash1 and \%hash2 didn't
solve the problem, though the format of the frozen
string differs from previously.  (It appears binary
and much less human readable if printed).

Using FreezeThaw::freeze did solve the problem. 
Thanks!

--- Adekunle Olonoh <[EMAIL PROTECTED]> wrote:
> > To give an idea why this might be useful:  I often
> > loop, calling a function which returns a list or
> hash,
> > and want to easily check if the list or hash I'm
> > getting back is one I have seen already. The
> following
> > doesn't work:
> > 
> >    my %seen;
> >    while(1)
> >       {
> >       my @list = some_func();
> >       die if($seen{\@list});
> >       $seen{\@list} = 1;
> >       }
> 
> You may have implemented your module this way, but
> serializing the data
> structure with a module like Data::Dumper will get
> you what you need:
> 
>     use Data::Dumper;
>     my %seen;
>     while(1) {
>         my @list = some_func();
>         my $serialized = Dumper(\@list);
>         die if $seen{$serialized};
>         $seen{$serialized} = 1;
>     }
> 
> You might want to also look at Storable and
> FreezeThaw.
> 
> -- 
> 
>
_______________________________________________________
> 
>      Ade Olonoh, BOTTLED SOFTWARE
> 
>      317.576.1120 x12 (phone) 317.576.1135 (fax)
>
_______________________________________________________
> 

__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

Reply via email to