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.
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'
In reply to Re: Multiple keys for a hash table row?
by Discipulus
in thread Multiple keys for a hash table row?
by mike65535
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |