chiburashka has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Binding an array to a word
by tachyon (Chancellor) on Aug 09, 2004 at 09:40 UTC

    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

    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.
Re: Binding an array to a word
by ysth (Canon) on Aug 09, 2004 at 09:25 UTC
    Can you explain what you mean by "give him a string"? Can you show what the code would look like except for the part you need help with? I don't understand what you want.
    A reply falls below the community's threshold of quality. You may see it by logging in.