Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks
How do you retrieve data from a DB_File
stored as storable, key wise
ie i want to retrieve the data
using a foreach statement
Thank you

Replies are listed 'Best First'.
Re: Storable retrieve
by djantzen (Priest) on Nov 07, 2002 at 01:18 UTC

    How are you storing the information to begin with? Do you mean you're using the Storable module to serialize the information first? If so, then I can't see why (or how) you'd then insert that into a DB_File. If on the other hand you're merely inserting a normal hash into a DB_File, then (from the documentation), use tie to load the data into a hash and merely foreach as normal over the keys:

    tie %hash, 'DB_File', [$filename, $flags, $mode, $DB_HASH]; foreach (keys %hash) { ... }

    Alternatively, after tie'ing the hash, you can use:

    $hash->get($key, $value [, $flags]);

      Alternatively, after tie'ing the hash, you can use:
      $hash->get($key, $value [, $flags]);
      But only if you define $hash ;)
      my $hash = tie %hash, 'DB_File', [$filename, $flags, $mode, $DB_HASH] +; $hash = tied %hash;
      If you do use $hash, you must be sure to undef it before you untie %hash, see the untie gotcha part of the DB_File documentation.

      ____________________________________________________
      ** The Third rule of perl club is a statement of fact: pod is sexy.

      Basically i want to store
      a hash directly in to an MLDBM
      I thgt using Storable will be faster
      But it is as the same speed as Data::Dumper
      hence if u can suggest something
      Thanks