in reply to Fast lookup for prefixes in hash
Here's a somewhat different way (no regex involved):
This finds the longest matching key in four iterations, then obtains the corresponding hash value. The exists function is used to avoid autovivifying false keys in %hash.my $number="31456000001"; my $len = (grep {exists $hash{substr($number,0,$_)}} 2..5)[-1]; my $result = $hash{substr($number,0,$len)};
After Compline,
Zaxo
|
|---|