Using Set::Scalar with DF_File

B

Brian Halligan

I would like to use DB_File to store and retrive a large number of
sets in a hash. I have been using Set::Scalar to create and compare
the sets, but I have been having trouble storing these sets using
DB_File. When I try to retrive the set based on a hash key, I get a
string that looks like the print version of the set. I would like it
to return a new set that I could then compare to others. Do I have to
'take apart' the print version and then recreate the set, or is there
a simple way to avoid this overhead and save and retrive the set
structure directly? Thanks.


Brian Halligan
Bioinformatics Research Center
Medical College of Wisconsin
 
J

Jim Keenan

Brian Halligan said:
I would like to use DB_File to store and retrive a large number of
sets in a hash.

Since you didn't post any code, we have to guess as to how you went about
this. In particular, what are you using as the key to store each hash?

I have been using Set::Scalar to create and compare
the sets, but I have been having trouble storing these sets using
DB_File. When I try to retrive the set based on a hash key, I get a
string that looks like the print version of the set.

Cf. the discussion in the Set::Scalar POD about the "display format" for a
Set::Scalar object. I recall getting tripped up on this when I first
studied this module.
I would like it
to return a new set that I could then compare to others. Do I have to
'take apart' the print version and then recreate the set, or is there
a simple way to avoid this overhead and save and retrive the set
structure directly? Thanks.
Perhaps you could use the 'members' method:

use Set::Scalar;
use Data::Dumper;

my @a0 = qw(abel abel baker camera delta edward fargo golfer);
my @a1 = qw(baker camera delta delta edward fargo golfer hilton);
my @a2 = qw(fargo golfer hilton icon icon jerky);
my @a3 = qw(fargo golfer hilton icon icon);
my @a4 = qw(fargo fargo golfer hilton icon);

my $s0 = Set::Scalar->new(@a0);
my $s1 = Set::Scalar->new(@a1);
my $s2 = Set::Scalar->new(@a2);
my $s3 = Set::Scalar->new(@a3);
my $s4 = Set::Scalar->new(@a4);

my %HoA = (
s0 => [ $s0->members ],
s1 => [ $s1->members ],
s2 => [ $s2->members ],
s3 => [ $s3->members ],
s4 => [ $s4->members ],
);

print Dumper(\%Hoa); # I think this may give you what you want

For a simpler interface, you may wish to consider the List::Compare module
available from CPAN. Full disclosure: I wrote it. But I've never tried it
in conjunction with DB_File. HTH

Jim Keenan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top