Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Day 1: There's a driver table that has four columns. (note: that's a lie, but a useful one.)

External_Name External_Value Internal_Name Internal_Value
I retrieve rather a lot of data from someplace. It comes in with External Name and Value fields. But we don't want to deal with the 'External_*' values. Instead they need to be translated to their internal equivalents. For instance we could have:
External_Name External_Value Internal_Name Internal_Value GLD_SPT PX_VALUE Gold Price AXXX111 PX_VALUE Frob Spread
and a data row would some in with "GLD_SPT,PX_VALUE" and I need to translate those to "Gold,Price" before sending the data down the pipe line.

But I REALLY don't want to be tagging the database for every row as I iterate across the set (which notably does NOT come from a database.) It's remarkably stupid given the volume. No problem, preload.

So I preloaded a hash with the following(ish.)

$Name_Resolver{lc("$External_Name|$External_Value")} = $Internal_Name;
and it actually works surprisingly well. For every row of data I get, I smack together a composite key and resolve it to Internal Name. The lookup table is prefetched. All happy nice nice.

Day 2: You should've seen this coming because it always happens to you. Yeah ok. But we need Internal_Value now as well....by tomorrow.

Ok, "by tomorrow" means add a parallel "%Value_Resolver" with the same composite string key that resolves to Internal_Value. It (of course) prefetches on the same load as the other hash.

And... sure. It works. But the whole approach makes me want to disavow it. The right "value" should be a simple list (or sub-hash? seems unnecessary) containing both values. But using a "two strings smacked together" key just seems wrong. I'm just not sure what would ACTUALLY be simpler (for values of 'simpler' approximating "easier for a programmer to understand.")

I'm in the peculiar position of being able to spend a (very) little time refactoring this code and cleaning it up a bit.

Thoughts?

EDIT: Been a while. I forget people can't read my mind for the rest of the context on these things. Hopefully this is a bit more clear.


In reply to A question of style: Composite keys to multiple values by Voronich

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-03-19 02:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found