For one thing, you are ignoring the first element of the array ( Perl arrays are zero-based ), and comparing phantom elements at the end of the array. For example, if you have this array:
@stuff = ( 90, 5, 4 );
Your code will start with the second element, and compare the last element to a nonexistent ( and therefore undefined ) value (
$stuff[3] ).
For another thing, you are resetting the value of
$highest every time a following element has a lower value. With the code as it now exists,
$highest will always be the last element in the array. I urge you to work this out by hand with the short example.
Here is something that does what you want:
my $highest = 0;
foreach my $element ( @numbers ) {
$highest = $element if $element > $highest;
}
print $highest;