Hello mike6535,
In the end I'd like to have several alternative "keys" per row, including some subset of abbreviations.
The behaviour you described is exactly what GetOpt::Long does with arguments. Take a loong breath and dive in it's source code to see how a real world wheel works.

Yes! you can reinvent the wheel (but see my signature..). In this case you can profit of the core module Text::Abbrev to have all unique abbreviations from a list, but you need to check for duplicates and collisions...

Probably have a dedicated sub to get the job done. Let's assume we want that the keys are in different languages and that values are just strings of words like in your example; something like (semitested!):
use strict; use warnings; my %multikeys; my %yet_used; # alternatives # value multikeyize ('colors|colores|farben|col|c',"red green purple"); multikeyize ('animals|animalia|a',"sheep cow dog"); # warning example: redefining a masterkey # multikeyize ('colors|xss|x',"tizio caio sempronio"); # warning example: redefining an alias # multikeyize ('c|xss|x',"tizio caio sempronio"); sub multikeyize{ my $alternatives= shift; my $value = shift; my @alternate = split /\|/,$alternatives; my $masterkey = shift @alternate; # masterkeys take the precedence.. if ($yet_used{$masterkey}){ print "\tWARNING '$masterkey' already defined! wiping previous + value!", ( $yet_used{$masterkey}=~/^1$/ ? "(was an alias)" : "(was a masterkey with value of '$yet_used{$masterkey} +')" ),"\n"; undef $yet_used{$masterkey}; } $multikeys{$masterkey} = $yet_used{$masterkey} = $value; map { $yet_used{$_}++; $multikeys{$_} = \$multikeys{$masterkey}; # just to show it.. print "$_->"; } grep {not exists $yet_used{$_} } @alternate; # just to show it.. print "(masterkey) $masterkey = '$multikeys{$masterkey}'\n\n"; } __OUTPUT__ colores->farben->col->c->(masterkey) colors = 'red green purple' animalia->a->(masterkey) animals = 'sheep cow dog'


HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Multiple keys for a hash table row? by Discipulus
in thread Multiple keys for a hash table row? by mike65535

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.