We're in the process of migrating between two different reporting systems at work, and part of this will involve converting client identifiers from 4-character strings to 7-character ones.

We're migrating incrementally, for various reasons (the systems are mission-critical, most importantly), and hence it's important that scripts and systems that already exist can interface, short-term, with the new code and systems put in.

To cope with the new client identifiers, I've created a hash that contains data for each client keyed on the new, 7-character, identifier, which was simple enough to do.

What I now need to do is find a way of having the old-style identifiers reference the new ones, so a call to, for example, $clients{ABCD} actually uses (and potentially modifies) the data in $clients{ABCDEFG}, rather than having to store the data twice and subsequently modify the data twice.

I've tried to do this using references, with the code below:

my %new_client_hash; foreach my $old_key (keys %clients) { my $new_key = $clients{$old_key}{new_sys_id}; delete $clients{$old_key}{new_sys_id}; $new_client_hash{$new_key} = $clients{$old_key}; $new_client_hash{$old_key} = \$new_client_hash{$new_key}; }
but this doesn't work - some of the new keys are "displaced" by the old keys, and some of the keys are simply left referencing an empty hash.

Does anyone know of a way to achieve this, or am I missing something obvious in the code there?

Any help would be appreciated.

Thanks,
-- Foxcub


In reply to Multiple keys describing a single hash element by Tanalis

Title:
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, details, 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, summary, 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.