我试图在 Perl6 中按年龄获取目录列表,这相当于 Bash ls -tl | grep ^dr
但我不确定如何按年龄对结果进行排序,如果这可能的话for dir (test => {$_.IO.d}) -> $dir {...}
如何按目录年龄对这些结果进行排序?
最佳答案
我想你要找的是:
dir(test => *.IO.d) .sort: *.changed
Afaik
-t
在 ls -tl
对应于 the IO::Path
method .changed
请注意,
dir
之间没有空格和 (test...)
.缺乏空间是非常重要的。在 P6,foo(bar,baz)
意味着与 foo (bar,baz)
完全不同的东西:# Call `foo` with two arguments `bar` and `baz`:
foo(bar, baz);
# Juxtapose identifier `foo` with a single `List` of 2 elements (bar, baz):
foo (bar,baz);
# Juxtapose identifier `foo` with two `List`s:
foo (bar,baz), (qux, waldo);
在后一种情况下,如果符号
&foo
已经声明(这是 sub foo ...
所做的)然后 foo
将被调用,就像第一种情况一样,但这次它将被调用 List
(两个元素)作为其唯一参数或两个参数(两个 List
s)。如果一个符号&foo
尚未声明,而是一个符号 foo
有,那么你会得到编译时语法错误。
关于raku - Perl6 : how to sort `dir` results by directory age?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57402171/