Programming Perl

Programming PerlSearch this book
Previous: 7.2.66 Test::Harness - Run Perl Standard Test Scripts with StatisticsChapter 7
The Standard Perl Library
Next: 7.2.68 Text::ParseWords - Parse Text into a List of Tokens
 

7.2.67 Text::Abbrev - Create an Abbreviation Table from a List

use Text::Abbrev;

%hash = ();
abbrev(*hash, LIST);

The abbrev() routine takes each string in LIST and constructs all unambiguous abbreviations (truncations) of the string with respect to the other strings in LIST. Each such truncation (including the null truncation consisting of the entire string) is used as a key in %hash for which the associated value is the non-truncated string.

So, if good is the only string in LIST beginning with g, the following key/value pairs will be created:

g    => good,
go   => good,
goo  => good,
good => good

If, on the other hand, the string go is also in the list, then good yields these key/value pairs:

goo  => good,
good => good

and go yields only:

go => go


Previous: 7.2.66 Test::Harness - Run Perl Standard Test Scripts with StatisticsProgramming PerlNext: 7.2.68 Text::ParseWords - Parse Text into a List of Tokens
7.2.66 Test::Harness - Run Perl Standard Test Scripts with StatisticsBook Index7.2.68 Text::ParseWords - Parse Text into a List of Tokens