mab has asked for the wisdom of the Perl Monks concerning the following question:
use BerkeleyDB; $create = ! -f 'data.dbm'; $db = new BerkeleyDB::Btree ( -Filename => 'data.dbm', -Flags => DB_CREATE ) or die "Cannot open file: $!"; if ( $create ) { for ( my $i = 1; $i <= 100000; $i++ ) { $db->db_put ( $i, "data" x 1000 ); } } $cursor = $db->db_cursor ( ); @keys = ( ); $key = 0; $value = 0; $status; for ( $status = $cursor->c_get ( $key, $value, DB_FIRST ); $status == 0; $status = $cursor->c_get ( $key, $value, DB_NEXT ) ) { push @keys, $key; } $cursor->c_close ( ); $db->db_close ( ); print ( $#keys + 1 ) . "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What is a fast way to get keys of a Berkeley DB into an array?
by zwon (Abbot) on Jun 09, 2010 at 18:45 UTC | |
by mab (Acolyte) on Jun 09, 2010 at 19:24 UTC | |
|
Re: What is a fast way to get keys of a Berkeley DB into an array?
by BrowserUk (Patriarch) on Jun 09, 2010 at 20:45 UTC | |
by mab (Acolyte) on Jun 10, 2010 at 15:38 UTC | |
by BrowserUk (Patriarch) on Jun 10, 2010 at 16:47 UTC | |
|
Re: What is a fast way to get keys of a Berkeley DB into an array?
by almut (Canon) on Jun 09, 2010 at 19:05 UTC | |
by mab (Acolyte) on Jun 09, 2010 at 19:37 UTC | |
by almut (Canon) on Jun 09, 2010 at 20:10 UTC |