<p>I've inherited a piece of code with a snippet which empties the database as follows:</p>

<pre><code>dbmopen (%db,"file.db",0666);
foreach $key (keys %db) {
  delete $db{$key};
}
dbmclose (%db);
</code></pre>

<p>This is usually okay but sometimes the database grows very large before this cleanup code is called and it's usually when a user wants to do something important.</p>

<p>Is there a better way of doing this?</p>

Actually, a workmate has pointed me to a solution.  You can apparently do:
```
```
dbmopen (%db,"file.db",0666);
%db = ();
dbmclose (%db);
```
```
which clears out the hash before closing the database.