Trying to get the maximum in an array that cannot contain negative numbers I tried:
my @v;
#...
my $max = 0;
$max = $_
if ($_ > $max)
foreach (@v);
I get a syntax error with perl 5.18.2.
However (1) statement($_) foreach (@v); and (2) $max = $_ if ($_ > $max); are both OK, and they do what they are supposed to do.
So if (1) and (2) are both valid statements, why can't they be combined in the pattern used for (1)?
Just that noone needs to suggest that; here's how I solved the problem using a different syntax:
foreach (@v) {
$max = $_
if ($_ > $max);
}