in reply to Re: A question a Tree::Trie
in thread A question a Tree::Trie

from the documentation prefix: Will return the longest entry in the trie that is a prefix of word.

usr/bin/perl use Tree::Trie; my $trie = Tree::Trie->new( { deepsearch => 'prefix' } ); $trie->add_data ("+61" => "Term", "+611411" => Outleg_1, "+6114110" +=> "Outleg_2" , "+65" => "Term_Ref", default => unknown ); $trie->lookup("+61"); $trie->lookup("+612");

Replies are listed 'Best First'.
Re^3: A question about Tree::Trie
by Athanasius (Archbishop) on Oct 18, 2017 at 07:22 UTC

    Hello jhuijsing,

    I think you missed this from the documentation:

    $trie->lookup(word, suffix_length)
    This method performs lookups on the trie. In list context, it returns a complete list of words in the trie which begin with word. In scalar context, the value returned depends on the setting of the 'deepsearch' option.

    So, the deepsearch option has effect only in scalar context:

    use strict; use warnings; use Tree::Trie; my $trie = Tree::Trie->new( { deepsearch => 'prefix' } ); $trie->add_data ( '+61' => 'Term', '+611411' => 'Outleg_1', '+6114110' => 'Outleg_2', '+65' => 'Term_Ref', default => 'unknown', ); my $result = $trie->lookup('+612'); print "+612: $result\n";

    Output:

    17:18 >perl 1830_SoPW.pl +612: +61 17:18 >

    But when you assign the result of lookup() to an array, you put the function call into list context, and the deepsearch option does not apply.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Thanks The perils of coding when you don't read all the documentation and try to use something new