It seems to be related to the hash table, yet you don't show us the table.

Anyway, one problem with your code is that you iterate over a hash, abort in the middle and don't reset the iterator.

Iterating over a hash is a bad idea anyway - just store it the other way round (ie turn the values into keys and the other way round), and do a lookup:

# assuming you have no duplicate values: my %mapkey = reverse %keymap; sub findCharacterAsKey { my $loebnerLetter = shift; if (exists $mapkey{$lobnerLetter}) { return $mapkey{$lobnerLetter}; } else { warn "Could not resolve '$loebnerLetter'"; } }

Since you have to do the inversion of the hash only once, it'll be much faster and correct this way.

Perl 6 - links to (nearly) everything that is Perl 6.

In reply to Re: File Reading and Hash Accessing that isn't doing what you'd expect. by moritz
in thread File Reading and Hash Accessing that isn't doing what you'd expect. by Chris_Stevens

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.