# from Bill Ward
# on Friday 13 February 2009 11:08:

>> What's wrong with Text::Abbrev?  It's been part of the core for a
>> long time.
>
>That might be the thing I'm looking for, thanks.

It does appear to have an issue with not detecting ambiguous 
abbreviations.

  my %hash = abbrev(qw(dog door));
  warn exists($hash{'do'});

If you want to tell the difference between that and a complete miss, you 
need to either rewrite that store the ambiguous items as undef, or 
like:

sub {
  my ($word, @words) = @_;

  my $match;
  for (@words) {
    if(m/^\Q$word\E(.*)$/) {
      return($_) unless(length $1); # exact
      croak("'$word' is ambiguous") if(defined $match);
      $match = $_;
    }
  }
  croak("'$word' not found") unless(defined $match);
  return($match);
}

But you might have a hash of your words, so you could just try for the 
exact match first and then grep(/^\Q$word\E/, keys %words) and check 
that you have exactly one hit.

--Eric
-- 
Moving pianos is dangerous.
Moving pianos are dangerous.
Buffalo buffalo buffalo buffalo buffalo buffalo buffalo.
---------------------------------------------------
    http://scratchcomputing.com
---------------------------------------------------

Reply via email to