From: Eric Schwartz Date: 2003-07-11T07:22:00+09:00 Subject: Re: Ruby T-Shirt Idea "Hal E. Fulton" writes: > I have little knowledge of Perl. > > Suppose you wanted to iterate through an array and > print out the odd-numbered elements: > > array.each_with_index {|x,i| puts x if i % 2 == 1 } > > How would that look in Perl? You're actually printing the indices of the elements which are odd. If you want to do that in Perl: $i=0; foreach (@array) { print "$i\n" if $_ % 2; $i++; } or for($i=0; $i<=@array; $i++) { print "$array[$i]\n" if $array[i] % 2; } If you want to print out the odd-numbered elements themselves: foreach (@array) { print "$_\n" if $_ %2; } -=Eric -- Come to think of it, there are already a million monkeys on a million typewriters, and Usenet is NOTHING like Shakespeare. -- Blair Houghton.