Masters, we have a customer Database where contacts are stored with all their relevant Data, but in 1st person singular only. Now it happens that these are czech customers And if someones name is Jim Beam, you donīt just say Dear Mr. Beam, but Vazeny Mr. Beame, instead. Now theres a bunch of rules how to flex the names to this form called Vocativ. The most interesting experience was, that czech people were talking to me that it is IMPOSSIBLE to do this automatically. It took me 10 minutes of thought and 5 minutes to code to come up with something like that:
#!/usr/bin/perl -w use strict; my $name = shift; &cz_vocativ_mask($name); sub cz_vocativ_mask { my $name = shift; # Important! The longest suffixes must be the last ones in this list. my %sufdata = ( a => 'o', s => 'si', k => 'ku', ar => 'ari', ic => 'ici', ec => 'ce', ek => 'ku', er => 'ere', # vec => 'evce', vec => 'veci', # Michal Svec is saying he likes this better ); foreach my $suffix (keys %sufdata) { if($name =~ /^(.*)$suffix$/) { print "Suffix $suffix -> $1$sufdata{$suffix}\n"; return; } } print " no rule apply -> $name\n"; }
Now this works great for me and some more rules and weīre at ~100%. The biggest culprit is, that it works for me only... As written in the sourcecode, the longest suffixes MUST be the last ones, as the longest suffixes MUST be examined as the first ones at runtime.

The problem is, that the above piece of code indeed does examine the longest pieces first, but the people who applied this code in the DB-system say, the order of examination is completedly random.

So the behaviour of keys seems different, but we canīt see any difference (same perl version, same OS) the only difference is, that the code is just part of other code (but as separate routine also) and runs on a machine with less memory where it doesnīt seem to work "right".

Any suggestions how to FORCE the examination of longest keys first?

Any help greatly appreciated

Ciao


In reply to Getting impossible things right (behaviour of keys) by PetaMem

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.