From: Dr.Ruud on
Peng Yu wrote:

> I'm wondering what is the shortest code to count the number of element
> in an array that are greater than some values. I'm just not familiar
> with perl enough to know what is the best way.
>
> A for-loop is the easiest way to think of.
>
> I also come up with the following way. But I'm not sure how to simply
> it in one line. I'm sure that there are better ways. Would you please
> let me know so that I can understand the expressive power of perl?
>
> @new_array=grep { $_ > 5 } @array;
> $#new_array+1

Per is a strongely typed language.
One type dimension is scalar-array/hash (context).
Another type dimension is enforced by operators (casting).


Example:

perl -wle '
my $odds = grep $_ % 2,
map rand($_),
( 314.15927 ) x 50;
print $odds;
'
30

--
Ruud