I'm a bit reluctant to sort a whole array if all that is needed is to find a maximum value, because the algorithmic complexity is higher (meaning it is in theory less efficient). Having said that, I must admit it probably does not matter unless then number of file is very high.
Anyway, you might avoid a sort with something like this:
my %hash
for my $file (glob("*.*")) {
my ($root, $ext) = split /\./, $file;
if (defined $hash{root) {
$hash{$root} = $ext if $ext > $hash{$root};
} else {
$hash{$root} = $ext;
}
}
The if ... else statement could be reduced to a simple if statement and a Boolean operator:
$hash{$root} = $ext if (not defined $hash{$root}) or $ext > $hash{$roo
+t};
but I wanted to make it as easy to read as possible.