Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Wildcard for key in hash lookup to skip over level

by rjt (Deacon)
on Dec 04, 2012 at 18:04 UTC ( #1007133=note: print w/ replies, xml ) Need Help??


in reply to Wildcard for key in hash lookup to skip over level

Edit

I spent a little time refactoring your code so I could make better sense of it. I still don't know exactly how the columns map to your text description. That being said, it looks like original suggestion, while often helpful, might not work in your case, if you will be re-using %Pos_overlap for something else.

If that's the case, you might indeed be better served with a more complex data structure (which could indeed mean two hashes (trees, actually), or sub-trees of the current hash). It will essentially be a memory/performance tradeoff; storing multiple representations takes more memory, but can reduce operations to ~O(1) that would otherwise be O(n).

It's looking like memory is probably not a concern, as you already read and store the complete contents both files in memory, in addition to the hash. If you convert your @var = (<FILE>) loops to while (<FILE>) { ... } loops, you can save a good deal of memory right now, for free.


The usual way to accomplish something like this is to write your own hashing function. In Perl, this is roughly equivalent to passing your preliminary key through some sort of filter subroutine before you access it. You probably have done something like $names{lc($name)}++ without even thinking about it.

This has a small cost (depending on how complex your function is), but if your potential wildcard expansion is more than a handful of elements (or even countably infinite...), it's a huge win.

By the way, your code was a bit hard to follow with the 200+ character lines, and would have made more sense if you would have labeled the column names like so:

my ($foo, $bar, $baz, $qux) = split /\t/;

(Of course replacing those names with whatever your columns should be called.)


Comment on Re: Wildcard for key in hash lookup to skip over level
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007133]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-12-21 15:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (106 votes), past polls