...
# add this line
my $maxval = 0;
foreach (@array) {
$maxval = $_ if $_ > $maxval; # and populate as needed here
print $_, "\t";
$counter ++;
if ($counter % 4 == 0) {
print "\n";
}
}
# then include the value in your final print statement
print "The largest element is: $maxval\n";
On the other hand, to use max as shown by Rolf do this:
use strict;
use List::Utils qw/max/; # add this line
... # rest of your code is unchanged
# and then use the function in your final print statement
print "The largest element is: " . max(@array) ."\n";
The answer to the question "Can we do this?" is always an emphatic "Yes!" Just give me enough time and money.
|