I want to execute
$filename = `ls *.gz | head -n 1`;
Execution of -e aborted due to compilation errors.
my $filename = (sort glob "*.gz");
You state the alphabeticall order thus the sort, which by default uses the "standard string comparison order" (see docs). Note that
ls can be aliased, while its defaults also may depend on the system.
Going out to the shell would make sense only if you were to use some particular strengths of
ls, that would take a lot of work to do in Perl. For mere sorting there is no reason to go out of your program. It is far less efficient and adds a whole list of new problems to solve.
A good point was raised by mob. Because of the invokation
sort BLOCK|SUB LIST one could wonder whether
glob could be taken in an unintended way. It's not, as that function runs first. However, this may well be just clearer
my ($filename) = sort (glob "*.gz");