#!/usr/bin/perl use feature(say); use strict; use warnings; use Text::CSV; use Tree::Trie; my $file = $ARGV[0] or die "Need to get CSV file on the command line\n"; my $csv = Text::CSV->new ({ binary => 1, auto_diag => 1, }); my($trie) = new Tree::Trie; open(my $data, '<:encoding(utf8)', $file) or die "Could not open '$file' $!\n"; while (my $fields = $csv->getline( $data )) { $trie->add_data(($fields->[0])=>($fields->[1])); my(@sent) = $trie->lookup_data($fields->[0]); #<-- only seems to get the right data in array context printf "Just added %s\n with sentiment %s\n", $fields->[0], @sent[1]; } if (not $csv->eof) { $csv->error_diag(); }