Using Set::Scalar with DF_File

Discussion in 'Perl Misc' started by Brian Halligan, Dec 23, 2003.

  1. 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
    Brian Halligan, Dec 23, 2003
    #1
    1. Advertising

  2. Brian Halligan

    Jim Keenan Guest

    "Brian Halligan" <> wrote in message
    news:...
    > 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
    Jim Keenan, Dec 24, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Clint Olsen
    Replies:
    6
    Views:
    336
    Jeff 'japhy' Pinyan
    Nov 13, 2003
  2. Regent
    Replies:
    9
    Views:
    132
    Jason Hood
    Dec 30, 2003
  3. J. Romano

    Using scalar() on function return values

    J. Romano, Jul 7, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    107
    J. Romano
    Jul 11, 2004
  4. Mark

    Replace scalar in another scalar

    Mark, Jan 27, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    152
    Arndt Jonasson
    Jan 27, 2005
  5. Gizbo
    Replies:
    7
    Views:
    112
    Ted Zlatanov
    Nov 28, 2007
Loading...

Share This Page