Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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":



  • 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 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? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2022-01-25 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (67 votes). Check out past polls.

    Notices?