Re: need sort help

2018-06-11 Thread ToddAndMargo
On 06/11/2018 12:12 AM, andreas.muel...@biologie.uni-osnabrueck.de wrote: ls -t Sort by the time stamp. That is cheating! :-)

Re: need sort help

2018-06-11 Thread Andreas.Mueller
ls -t :-) On 08.06.18 17:15, ToddAndMargo wrote: > Hi All, > > https://docs.perl6.org/routine/sort > > How do I fix this? > > $ ls | perl6 -e 'my @x=slurp(); say @x.sort' > (log.06-08-2018_16:07:39.zip > log.06-08-2018_17:07:39.zip > log.07-08-2018_06:07:39.zip >

Re: need sort help

2018-06-09 Thread Xin Cheng
Got it, thanks. Xin > On Jun 9, 2018, at 4:07 PM, Brandon Allbery wrote: > > And in the others, you've provided an explicit invocant with " some kind>.sort", so again it knows it's a method call and has an invocant > already. > > A sub can be forced to be a method call instead by using ":"

Re: need sort help

2018-06-09 Thread Brandon Allbery
And in the others, you've provided an explicit invocant with ".sort", so again it knows it's a method call and has an invocant already. A sub can be forced to be a method call instead by using ":" and providing the invocant *before* the colon: say sort(<3 5 2 1>: {$^a <=> $^b}) On Sat, Jun 9,

Re: need sort help

2018-06-09 Thread Xin Cheng
Thanks. But I am actually confused by the use of colon in Sort: { ... } What does it mean in the above statement? I have done several experiments like: p6 'say sort({$^a <=> $^b}, < 3 5 2 1>)'# (1 2 3 5) p6 'say <3 5 2 1>.sort({$^a <=> $^b})' # it works. p6 'say <3 5 2

Re: need sort help

2018-06-09 Thread Brandon Allbery
The ".=" operator means call the method on the right, with the thing on the left as invocant, and assign the result back to the thing on the left. So @x .= sort: ... is the same as @x = @x.sort(...) So you're being confused by the syntactic "magic" of ".=". On Sat, Jun 9, 2018 at 2:58

Re: need sort help

2018-06-09 Thread Xin Cheng
I got the point for //. Another question is about calling the method sort with a code block. I can understand @x .= sort({ ... }); But I don't quite understand why this form also works. @x .= sort: { ... }; I look into the documentation for infix ":", https://docs.perl6.org/routine/:

Re: need sort help

2018-06-09 Thread Brandon Allbery
More precisely, at that point you have a bunch of numbers, but possibly not as many as expected if some of the components weren't numeric (or all of them, as when there are files present that aren't the expected logs). Which means some or all of those variables will be undefined instead of

Re: need sort help

2018-06-09 Thread Timo Paulssen
The magic trick is that the last line in the code block is the return value. when you pass a function that takes a single argument (in this case just the $_) to sort, it will call your function for every element in the input array and use the result of that function to sort the elements by. The

Re: need sort help

2018-06-08 Thread ToddAndMargo
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,

Re: need sort help

2018-06-08 Thread Timo Paulssen
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. 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

Re: need sort help

2018-06-08 Thread ToddAndMargo
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,

Re: need sort help

2018-06-08 Thread Timo Paulssen
If you want to make it robust in the case of fields being different length, like having entries with the day as "5" instead of "05", you can put a >>.Int after the .comb(/\d+/) and that'll give you proper numeric sorting for all fields regardless of width. On 09/06/18 06:51, Timo Paulssen wrote:

Re: need sort help

2018-06-08 Thread Timo Paulssen
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:

Re: need sort help

2018-06-08 Thread ToddAndMargo
On 06/08/2018 09:44 PM, Brent Laabs wrote: It isn't in any variable, @x.sort got called in sink context.  You'll have to assign it if you want, maybe use @x.=sort ? Is alright. I didn't understand what was happening anyway. Thank you for the help!

Re: need sort help

2018-06-08 Thread Brent Laabs
It isn't in any variable, @x.sort got called in sink context. You'll have to assign it if you want, maybe use @x.=sort ? I just wanted to give an example of how to solve the problem, not necessarily a working solution. First of all, I did thinko the solution -- element 6 is [5]... and we don't

Re: need sort help

2018-06-08 Thread ToddAndMargo
On 06/08/2018 09:25 PM, Brandon Allbery wrote: @x.sort: {    my $a = $^x ~~ m:g/\d+/;    my $b = $^y ~~ m:g/\d+/;    $a[6].defined cmp $b[6].defined    ??      $a[3] cmp $b[3]    || $a[1] cmp $b[1]    || $a[2] cmp $b[2]    || $a[4] cmp $b[4]    || $a[5] cmp $b[5]    || $a[6] cmp $b[6]

Re: need sort help

2018-06-08 Thread ToddAndMargo
On 06/08/2018 09:25 PM, Brandon Allbery wrote: @x.sort: {    my $a = $^x ~~ m:g/\d+/;    my $b = $^y ~~ m:g/\d+/;    $a[6].defined cmp $b[6].defined    ??      $a[3] cmp $b[3]    || $a[1] cmp $b[1]    || $a[2] cmp $b[2]    || $a[4] cmp $b[4]    || $a[5] cmp $b[5]    || $a[6] cmp $b[6]

Re: need sort help

2018-06-08 Thread Brandon Allbery
@x.sort: { my $a = $^x ~~ m:g/\d+/; my $b = $^y ~~ m:g/\d+/; $a[6].defined cmp $b[6].defined ?? $a[3] cmp $b[3] || $a[1] cmp $b[1] || $a[2] cmp $b[2] || $a[4] cmp $b[4] || $a[5] cmp $b[5] || $a[6] cmp $b[6] || $x cmp $y !! $x cmp $y }; This is what I sent

Re: need sort help

2018-06-08 Thread ToddAndMargo
On 06/08/2018 09:16 PM, Brandon Allbery wrote: You didn't use what I sent. It's $^x and $^y, not $a and $b. I am lost. Would you mind writing it out for me?

Re: need sort help

2018-06-08 Thread Brandon Allbery
You didn't use what I sent. It's $^x and $^y, not $a and $b. (Aside: I *really* wish placeholders didn't work that way; this thread is demonstrating why it's a bad idea. Not to mention a pain in the butt.) On Sat, Jun 9, 2018 at 12:12 AM ToddAndMargo wrote: > >>> @x.sort: { > >>>my $a =

Re: need sort help

2018-06-08 Thread ToddAndMargo
@x.sort: { my $a = $^x ~~ m:g/\d+/; my $b = $^y ~~ m:g/\d+/; $a[6].defined cmp $b[6].defined ?? $a[3] cmp $b[3] || $a[1] cmp $b[1] || $a[2] cmp $b[2] || $a[4] cmp $b[4] || $a[5] cmp $b[5] || $a[6] cmp $b[6] || $x cmp $y !! $x cmp $y }; On Fri, Jun 8, 2018

Re: need sort help

2018-06-08 Thread Brandon Allbery
Brent thinkoed that slightly. (Forgot that first use of a placeholder "declares" it, and thereafter you don't use the ^. Which then collides with the local "my" variables.) > @x.sort: { >my $a = $^x ~~ m:g/\d+/; >my $b = $^y ~~ m:g/\d+/; >$a[6].defined cmp $b[6].defined >?? >

Re: need sort help

2018-06-08 Thread ToddAndMargo
On 06/08/2018 07:00 PM, Brent Laabs wrote: let me revise that @x.sort: {   my $a = $^a ~~ m:g/\d+/;   my $b = $^b ~~ m:g/\d+/;   $a[6].defined cmp $b[6].defined   ??     $a[3] cmp $b[3]   || $a[1] cmp $b[1]   || $a[2] cmp $b[2]   || $a[4] cmp $b[4]   || $a[5] cmp $b[5]   || $a[6] cmp

Re: need sort help

2018-06-08 Thread ToddAndMargo
>> On Fri, Jun 8, 2018 at 6:50 PM, ToddAndMargo > > wrote: >> >> On Fri, Jun 8, 2018 at 5:15 PM, ToddAndMargo >> mailto:toddandma...@zoho.com> >> >

Re: need sort help

2018-06-08 Thread Brent Laabs
let me revise that @x.sort: { my $a = $^a ~~ m:g/\d+/; my $b = $^b ~~ m:g/\d+/; $a[6].defined cmp $b[6].defined ?? $a[3] cmp $b[3] || $a[1] cmp $b[1] || $a[2] cmp $b[2] || $a[4] cmp $b[4] || $a[5] cmp $b[5] || $a[6] cmp $b[6] || $^a cmp $^b !! $^a cmp $^b }; On Fri,

Re: need sort help

2018-06-08 Thread Brent Laabs
If possible, you should change the way the files come, or rename them when you get them, or open an issue to use a proper output log format. I mean, you can sort like: @x.sort: { my $a = $^a ~~ m:g/\d+/; my $b = $^b ~~ m:g/\d+/; $a[6].defined cmp $b[6].defined ?? || $a[3] cmp $b[3] ||

Re: need sort help

2018-06-08 Thread ToddAndMargo
On Fri, Jun 8, 2018 at 5:15 PM, ToddAndMargo > wrote: Hi All, https://docs.perl6.org/routine/sort How do I fix this? $ ls | perl6 -e 'my @x=slurp(); say @x.sort' (log.06-08-2018_16:07:39.zip

Re: need sort help

2018-06-08 Thread Curt Tilmes
> > On Fri, Jun 8, 2018 at 5:15 PM, ToddAndMargo > wrote: >> >> How do I fix this? >> >> $ ls | perl6 -e 'my @x=slurp(); say @x.sort' >> (log.06-08-2018_16:07:39.zip >> log.06-08-2018_17:07:39.zip >> log.07-08-2018_06:07:39.zip >> log.07-08-2018_16:07:39.zip >> log.12-08-2016_06:07:39.zip >> ) >>

Re: need sort help

2018-06-08 Thread Brent Laabs
Rename all of the input files using ISO 8601 dates. I can't tell, from looking at those numbers, if the first field is the month or the day, so it's impossible to sort data like that with certainty. On Fri, Jun 8, 2018 at 5:15 PM, ToddAndMargo wrote: > Hi All, > >

need sort help

2018-06-08 Thread ToddAndMargo
Hi All, https://docs.perl6.org/routine/sort How do I fix this? $ ls | perl6 -e 'my @x=slurp(); say @x.sort' (log.06-08-2018_16:07:39.zip log.06-08-2018_17:07:39.zip log.07-08-2018_06:07:39.zip log.07-08-2018_16:07:39.zip log.12-08-2016_06:07:39.zip ) 2016 should be at the top. Many thanks,