in reply to arrays and strings

my @numbers = (1, 2, 2, 3, 3); my @strings = qw(hello green grass rainbow pretty); my @check = (1, 2, 3, 4); my @new_strings; foreach (@numbers) { die "string $_ does not exists" unless defined $strings[$_-1]; $new_strings[$_-1] .= $strings[$_-1]; } foreach (@check) { $new_strings[$_-1] = 'xxxxxx' unless defined $new_strings[$_-1]; } print $_, "\n" for grep defined, @new_strings;

Update: filtered output, indexes corrected

Replies are listed 'Best First'.
Re^2: arrays and strings
by Anonymous Monk on Aug 31, 2004 at 14:20 UTC
    hi ccn! thanks for your help, but i can't get this to work right. my outputm from it is:
    green grassgrass rainbowrainbow xxxxxx green grassgrass rainbowrainbow xxxxxx green grassgrass rainbowrainbow xxxxxx green grassgrass rainbowrainbow xxxxxx
    I need:
    hello greengrass rainbowpretty xxxxxxxx # where @numbers basically refers to which line the strings should be +printed to