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

Re: need sort help

Thread Previous | Thread Next
From:
ToddAndMargo
Date:
June 9, 2018 05:42
Subject:
Re: need sort help
Message ID:
425f9037-549e-1653-fbe2-39853884b0ee@zoho.com
>> On 09/06/18 07:23, ToddAndMargo wrote:
>>> On 06/08/2018 09:51 PM, Timo Paulssen wrote:
>>>> That's unnecessarily long and complicated, here's how you can do it much
>>>> easier:
>>>>
>>>>       @x.sort: {
>>>>           my ($month, $day, $year, $hour, $minute, $second) =
>>>> .comb(/\d+/);
>>>>           ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
>>>> $second // 0, $_);
>>>>       }
>>>>
>>>> Trying it on some input data:
>>>>
>>>>       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
>>>>       cimtrak.log.12-08-2016_06:07:39.zip
>>>>       cookies
>>>>       asbestos
>>>>       fire engine
>>>>       perl6
>>>>       butterflies
>>>>
>>>> results in:
>>>>
>>>>       asbestos
>>>>       butterflies
>>>>       cookies
>>>>       fire engine
>>>>       perl6
>>>>       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
>>>>
>>>> This is the schwartzian transform that was mentioned in another mail.
>>>> why it wasn't actually shown, i have no clue :)
>>>>
>>>> Hope that helps
>>>>     - Timo
>>>>
>>>
>>>
>>> What am I doing wrong?
>>>
>>> $ ls | perl6 -e 'my @x=slurp();  say @x.sort: {my ($month, $day,
>>> $year, $hour, $minute, $second) = .comb(/\d+/);($year // 0, $month //
>>> 0, $day // 0, $hour // 0, $minute // 0,$second // 0, $_);}'
>>> (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
>>> cimtrak.log.12-08-2016_06:07:39.zip
>>> )
> 

On 06/08/2018 10:24 PM, Timo Paulssen wrote:
> your list @x has only a single item, because you're slurping the whole
> file contents into it.
> 
> replacing slurp with lines should do the trick.
> 
> 

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

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