Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??


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.)

In reply to Re: Wildcard for key in hash lookup to skip over level by rjt
in thread Wildcard for key in hash lookup to skip over level by ZWcarp

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (8)
    As of 2019-10-21 23:15 GMT
    Find Nodes?
      Voting Booth?