develooper Front page | perl.perl6.users | Postings from June 2018

Re: need sort help

Thread Previous | Thread Next
From:
Bruce Gray
Date:
June 9, 2018 23:08
Subject:
Re: need sort help
Message ID:
247F6D51-5A95-4E25-B447-FD472633D909@acm.org

> On Jun 9, 2018, at 12:42 AM, ToddAndMargo <ToddAndMargo@zoho.com> wrote:
—snip--
> Yippee!!  Thank you!
> 
> $ ls | perl6 -e 'my @x=lines();  for @x.sort: {my ($month, $day, $year, $hour, $minute, $second) = .comb(/\d+/);($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,$second // 0, $_);} -> $Line {say $Line};'
> cimtrak.log.12-08-2016_06:07:39.zip
> cimtrak.log.06-08-2018_16:07:39.zip
> cimtrak.log.06-08-2018_17:07:39.zip
> cimtrak.log.07-08-2018_06:07:39.zip
> cimtrak.log.07-08-2018_16:07:39.zip

I see this is well solved, but here is Yet Another Way to do it:
ls | perl6 -e '.say for lines().sort: {
    ( (/ (\d\d)"-"(\d\d)"-"(\d\d\d\d)"_"(\d\d)":"(\d\d)":"(\d\d) / ?? "$2$0$1$3$4$5" !! ""), $_ )
}'


— 
Hope this helps,
Bruce Gray (Util of Perlmonks)
Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About