lib/Text/Trie.pm |
Text::Trie
use Text::Trie qw(Trie walkTrie); @trie = Trie 'abc', 'ab', 'ad'; walkTrie sub {print("[",shift,"]")}, sub {print(shift)}, sub {print "->"}, sub {print ","}, sub {print "("}, sub {print ")"}, @trie;
Trie
Arguments are split into groups according to the first letter. If group consists of one element, it results in the string element in the output array. If group consists of several elements, then the corresponding element of output array looks like
[$head, ...]
where $head is the common head of the group, the rest is the result of
recursive application of Trie
to tails of elements of the group.
walkTrie
Trie
, the routine walks over the tree
depth-first. If element of the array is a reference to array, it is
interpreted as a node, and the walkTrie
is applied to the
corresponding array (without the first element) recursively. Otherwise the
element is interpreted as a leaf of the tree.
Subroutines are executed when (in the order of arguments of walkTrie
):
Any one of the first six arguments can be undef
instead of being a
reference to a subroutine.
None by default, Trie
and walkTrie
are @EXPORTABLE.
Variable $Text::Trie::step can be set to a value bigger than 1 to set the length of smallest units arguments can be broken into.
Contact Ilya Zakharevich, ilya@math.ohio-state.edu.
lib/Text/Trie.pm |