in reply to Re^2: Finding target unspecified value
in thread Finding target unspecified value
Do this to use my idea:
... # 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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Finding target unspecified value
by Latnam (Novice) on Oct 20, 2013 at 21:19 UTC |