Hello,
I think your problem is that <STDIN> is not returning an list. It's putting all the values in to $list[0]. I made two changes to your code and it seams to work.
#!/usr/bin/perl @names = qw/ fred betty barney dino wilma peblles bamm-bamm /; chomp($list = <STDIN>); @list = split /\s+/,$list; foreach (@list) { print "$names[ $_ - 1 ]\n"; }
Hope this helps.
In reply to Re: A simple foreach question
by rlb3
in thread A simple foreach question
by newperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |