in reply to Binding an array to a word

Just use a hash to map the word to the array. The array will be stored as an array ref and the keys are case sensitive. See perlman:perlreftut.

my $h = { hello => [ 1, 2, 3, 4 ], world => [ 5, 6, 7, 8 ], }; my $str = 'Hello World, Just another hello hack!'; for my $word( split /\W+/, $str ) { my $key = lc($word); my $mapping = exists $h->{$key} ? $h->{$key} : [ '#???#' ]; print "$word\t@$mapping\n"; } __DATA__ Hello 1 2 3 4 World 5 6 7 8 Just #???# another #???# hello 1 2 3 4 hack #???#

cheers

tachyon

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.