in reply to A simple foreach question
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: A simple foreach question
by betterworld (Curate) on Mar 06, 2005 at 16:55 UTC |