Hello,
I have written modules for mapping certain complex
data structures by value to scalars. I am looking for
input on whether I have duplicated another class, or
worse, perl built in functionality of which I am not
aware.
The classes I have written are tentatively named
Map::Hash, Map::Set, Map::Bag, and Map::List. They
fulfill the same purpose as a perl built-in hash,
except that they accept more interesting keys such as
lists, hashes, sets (represented as perl lists), and
bags (also represented as perl lists).
For instance:
use Map::Hash;
my $map = new Map::Hash();
$map->set( { "Randall" => "Schwartz",
"Larry" => "Wall",
"Tom" => "Christiansen" },
"perl authors" );
$map->set( { "Jon" => "Swartz" },
"mason" );
$map->set( { "foo" => 1 } );
my $a = $map->get( { "Jon" => "Swartz" } );
would result in $a being assigned "mason", even though
the hash reference used in method get() is not the
same reference as the one used in method set(). This
is what I mean by "by value". These two distinct
references are considered equal because they represent
equal hashes.
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;
}
However, this does:
my $seen = new Map::List();
while(1)
{
my @list = some_func();
die if($seen->get(\@list));
$seen->set(\@list,1);
}
Map::List, Map::Hash, Map::Set, and Map::Bag all have
similar interfaces. They differ in how they determine
equality.
Thanks for any advice, including advice on whether I
should consider renaming these classes.
I will post a more detailed explanation of these
modules if the response I get indicates that these
might be a unique contribution to CPAN.
Mark Dilger
[EMAIL PROTECTED]
__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/