If you look again at the synopsis in the Tree::Trie
documentation that you linked to, you will see that the trie is only created once (my($trie) = new Tree::Trie;
- although this should be written as my $trie = Tree::Trie->new;
rather than using indirect object notation) and data is only added to it once ($trie->add(...);
), and then the trie is used for multiple lookups (my(@all) = $trie->lookup("");
and my(@ms) = $trie->lookup("m");
).
The way to create the trie once and then use it for lookups, then, is to simply keep the $trie
variable around (in scope) and use it for all your lookups instead of creating new Tree::Trie
instances each time.
If this answer isn't useful to you, please update your question to include a small, self-contained, runnable example program showing how you're using Tree::Trie
and we can show you how to modify it so that the trie only gets built once.