I'm trying to determine the maximum number of digits of any number in a list. I've found that I can easily chain functions. As such the following code works as expected:
use strict;
use diagnostics;
my @nums = qw/ 1 23 5432 45 /;
my @lengths = reverse sort map {1 + log($_)/log(10)} @nums;
my $max_length = shift @lengths;
printf "%d\n", $max_length;
Which produces the expected result of 4.
However, when I try to do the shift on the same line as the rest of the list operations:
use strict;
use diagnostics;
my @nums = qw/ 1 23 5432 45 /;
my $max_length = shift reverse sort map {1 + log($_)/log(10)} @nums;
printf "%d\n", $max_length;
I get the error
Experimental shift on scalar is now forbidden at - line 5, near "@nums;"
Why does shift think that it's being passed a parameter with scalar context, but reverse and sort don't?
Thanks