failing to get a data retrieval in scalar context to function; it would always just return the word again.I tried your code and using scalar context worked for me, i.e. it returned the data associated with the word, not the word itself.
Output:use Tree::Trie; my $trie = new Tree::Trie; $trie->add_data( word => 'data'); my @sent = $trie->lookup_data('word'); print "List context: @sent\n"; my $data = $trie->lookup_data('word'); print "Scalar context: $data\n";
Maybe you could post up some of your input file? It would help to answer your second question as well.List context: word data Scalar context: data
Update: Is it possible you are using "scalar context" like this:
If so, that will indeed return the word and not the data, you need to leave out the brackets around $datamy ($data) = $trie->lookup_data($fields->[0]);
In reply to Re: Scalar data & collection data with Tree::Trie
by tangent
in thread Scalar data & collection data with Tree::Trie
by Endless
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |