in reply to two hashes occupying the same space
What you're asking for is a way to gain easy lookups, where the keys of hash1 refer to the same values that are the keys of hash2, and vice versa.
I can see the logic here. Hash lookups are O(1) in speed efficiency, whereas greping for a value is O(n). But the problem is that maintaing a pair of hashes that crossreference each other gains speed at the cost of memory.
When you find yourself in such a situation, it is often time to start thinking in terms of a relational database. Even if all you have are two columns, it makes sense to let the database engine deal with quickly locating your information for you. Let's say you have the following database table:
name | title --------|---------------- bart | troublemaker homer | delinquent dad marge | enabling mother maggie | wise baby lisa | child prodigy
You could perform lookups by name by using an SQL query such as this one:
SELECT title FROM jobs WHERE name='bart'Or you could let the database search based on the other column instead...
SELECT name FROM jobs WHERE title='troublemaker'The database engine is usually pretty good at doing lookups in very rapid time. Perl makes database work easy (or at least possible) using the DBI module. DBI is the Perl-side interface to your database. It still needs an actual database too. A very simple, easy to use, easy to install, single-file kind of database will do, and for that, DBD::SQLite is a great tool.
I hope this alternate approach is helpful.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: two hashes occupying the same space
by tilly (Archbishop) on Oct 28, 2004 at 05:26 UTC | |
by davido (Cardinal) on Oct 28, 2004 at 05:30 UTC | |
by tilly (Archbishop) on Oct 28, 2004 at 05:35 UTC | |
by davido (Cardinal) on Oct 28, 2004 at 05:45 UTC | |
|
Re^2: two hashes occupying the same space
by BrowserUk (Patriarch) on Oct 28, 2004 at 05:36 UTC | |
by davido (Cardinal) on Oct 28, 2004 at 06:00 UTC |