in reply to How to create a compact data structure?

You can get rid of the hash refs, and use one big hash with exists for the flags. Then you can just assign undef for true, which is cheap.
foreach my $item (LARGE_LIST) { $key = property($item); $record{$key}++; if(condition_is_true($item)) { $flag{$key} = undef; } } # later if (exists $flag{$key}) { # flag is on }

Replies are listed 'Best First'.
Re^2: How to create a compact data structure?
by bart (Canon) on Dec 20, 2006 at 11:47 UTC
    This is pretty clever, especially since more recent perls allegedly store common keys for different hashes in one, single place.

    I wonder if (and how) you can reliably use Devel::Size to measure how much memory is used by both hashes...?

      I don't know about 'reliable' but 'how' should work like this:
      use Devel::Size qw(total_size); # code by perrin my $size_rec_hash = total_size(\%record); my $size_flag_hash = total_size(\%flag); print "Total size: $size_rec_hash + $size_flag_hash =", $size_rec_hash + $size_flag_hash, "\n";
      Update: I missed the point, please ignore.

      -- Hofmator

      Code written by Hofmator and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

        You are totally ignoring the fact that these hashes have many keys in common, as every single key in %flag is also a key in %record. And that was precisely the point I was asking about.