Note the description of List::MoreUtils
:
List::MoreUtils provides some trivial
but commonly needed functionality on
lists which is not going to go into
List::Util.
The minmax sub in List::MoreUtils will work but compare numerical values, instead of string lengths. However, minmax can be adapted quite easily to instead compare the lengths of its arguments.
sub minmax_stringlength (@) {
return unless @_;
my $min = my $max = $_[0];
for ( my $i = 1; $i < @_; $i += 2 ) {
if ( length($_[$i-1]) <= length($_[$i]) ) {
$min = $_[$i-1] if length($min) > length($_[$i-1]);
$max = $_[$i] if length($max) < length($_[$i]);
} else {
$min = $_[$i] if length($min) > length($_[$i]);
$max = $_[$i-1] if length($max) < length($_[$i-1]);
}
}
if ( @_ & 1 ) {
my $i = $#_;
if (length($_[$i-1]) <= length($_[$i])) {
$min = $_[$i-1] if length($min) > length($_[$i-1]);
$max = $_[$i] if length($max) < length($_[$i]);
} else {
$min = $_[$i] if length($min) > length($_[$i]);
$max = $_[$i-1] if length($max) < length($_[$i-1]);
}
}
return ($min, $max);
}
Note, I did not write the above, I merely added length in the comparisons where before the mere number was being compared. Unfortunately I could not test this because I do not know how the AutoLoader works and I kept getting:
Use of inherited AUTOLOAD for non-method List::MoreUtils::minmax_stringlength() is deprecated at script.pl line 9.
So if the OP finds himself using find max very often he could just exercise his license and modify MoreUtils to provide that functionality.
If somebody more knowledgeable could verify that the above would work please do.