如何在Perl中从ls -lrt的输出中仅查找/剪切文件名

pau*_*ler -1 linux perl cut

我想从输出的文件名ls -lrt,但我无法找到文件名.我使用下面的命令,但它不起作用.

$cmd=' -rw-r--r-- 1 admin u19530 3506 Aug  7 03:34 sla.20120807033424.log';
my $result=`cut -d, -f9 $cmd`;
print "The file name is $result\n";
Run Code Online (Sandbox Code Playgroud)

结果是空白的.我需要文件名为sla.20120807033424.log


到目前为止,我已经尝试了下面的代码,它适用于文件名.

#!/usr/bin/perl
my $dir = <dir path>;
opendir (my $DH, $dir) or die "Error opening $dir: $!";
my %files = map { $_ => (stat("$dir/$_"))[9] } grep(! /^\.\.?$/, readdir($DH));
closedir($DH);
my @sorted_files = sort { $files{$b} <=> $files{$a} } (keys %files);
print "the file is $sorted_files[0] \n";
Run Code Online (Sandbox Code Playgroud)

ike*_*ami 8

use File::Find::Rule qw( );
use File::stat       qw( stat );
use List::Util       qw( reduce );

my ($oldest) =
   map $_ ? $_->[0] : undef,                              # 4. Get rid of stat data.
   reduce { $a->[1]->mtime < $b->[1]->mtime ? $a : $b }   # 3. Find one with oldest mtime.
   map [ $_, scalar(stat($_)) ],                          # 2. stat each file.
   File::Find::Rule                                       # 1. Find relevant files.
      ->maxdepth(1)                                       #       Don't recurse.
      ->file                                              #       Just plain files.
      ->in('.');                                          #       In whatever dir.
Run Code Online (Sandbox Code Playgroud)