Thanks for all the great answers, especially those with code samples and benchmarks! It looks like the syntax and space efficiency winner is Set::Light, though not by much (it uses a C module to point all the set members to a single object).

Remember I'm in mod_perl, so construction/deconstruction time is less important than memory footprint and lookup time.

#! /usr/bin/perl -w use strict; use Devel::Size qw(total_size); use Set::Light; my $lookup = "shave"; my %hash1 = ( shave => '', the => '', very => '', modern => '', way => '', ); my %hash2 = ( shave => 1, the => 1, very => 1, modern => 1, way => 1, ); my %hash3 = ( shave => undef, the => undef, very => undef, modern => undef, way => undef, ); print "Hash3 " . ((exists $hash3{$lookup})?"contains":"does not contai +n") . " $lookup\n"; my $foo = undef; my %hash4 = ( shave => \$foo, the => \$foo, very => \$foo, modern => \$foo, way => \$foo, ); my $set = Set::Light->new( qw/shave the very modern way/ ); print "Set " . (($set->has($lookup))?"contains":"does not contain") . +" $lookup\n"; print "Size 1: " . total_size(\%hash1) . "\n"; print "Size 2: " . total_size(\%hash2) . "\n"; print "Size 3: " . total_size(\%hash3) . "\n"; print "Size 4: " . total_size(\%hash4) . "\n"; print "Size S: " . total_size(\$set) . "\n"; __END__
Hash3 contains shave
Set contains shave
Size 1: 363
Size 2: 303
Size 3: 283
Size 4: 315
Size S: 251

In reply to Re: Effecicncy of key-only hash by brycen
in thread Effecicncy of key-only hash by brycen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.