A line in BrowserUK's post reminded me of one of my cobwebs that I'm always chasing, namely, whether the Conditional Operator, ?:, is preferable over sort. In the end I should import a max function when possible, but I don't always do so.

Conditional operator:

my $n = $x > $y ? $x : $y;

I find this awkward to read, and it also duplicates the variable names.


my $n = (sort {$a <=> $b} $x, $y)[-1];

But because sort needs a numeric sort function, that's a bit long winded.

And the max function:

use List::Util qw(max); my $n = max($x, $y);

Which seems to be the laziest and preferred way.

Quantum Mechanics: The dreams stuff is made of