I am trying to get a list of directories by age in Perl6, which is equivalent to Bash ls -tl | grep ^dr
but I am unsure how to sort the results by age, if this is even possible
for dir (test => {$_.IO.d}) -> $dir {...}
how can I sort these results by directory age?
I think what you're looking for is:
dir(test => *.IO.d) .sort: *.changed
Afaik the -t
in ls -tl
corresponds to the IO::Path
method .changed
Note that there's no space between dir
and (test...)
. That lack of space is very important. In P6, foo(bar,baz)
means something completely different than 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);
In the latter cases, if a symbol &foo
has been declared (which is what a sub foo ...
does) then foo
will be called, just as it was with the first case, but this time it'll be with either one List
(of two elements) as its only argument or two arguments (two List
s). If a symbol &foo
has not been declared but a symbol foo
has, then you'll get compile-time syntax error.
Use nqp::stat:
use nqp;
my @sorted = dir($*CWD).sort({ nqp::stat($_.Str, nqp::const::STAT_CREATETIME) });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With