Re: Sorting Multidimentional Arrays

2016-10-01 Thread Joan Pujol

El Saturday, 01 de October del 2016 a les 20:44, Moritz Lenz va escriure:


On 01.10.2016 19:57, mimosinnet wrote:

@opposite = @opposite.sort({@$^a[3]});


For the record, you can simplify this a bit:

@opposite = @opposite.sort(*[3]);


Waw! It works! Many thanks! 

I am still puzzled by the asterisk. I will have to dig more into the 
documentation :D :)


Cheers! 


for @opposite -> $line { say $line; }
---

I have adapted this from:
http://www.wellho.net/resources/ex.php?item=p600/mapper

I wanted to ask about the syntax, buy I have understood it while
writing the message ;) :D


I've had the same experience a few times :-)

Cheers,
Moritz

--
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


--
Joan Pujol Tarrés
Departament de Psicologia Social
Facultat de Psicologia, Universitat Autònoma de Barcelona
Despatx: B5-036 (Passadís Departament Psicologia Social)
Edifici B, 08193 Bellaterra (Barcelona), Fax: +34 935812001
http://psicologiasocial.uab.es/ca/user/43
http://psicologiasocial.uab.es/fic
http://orcid.org/-0002-0462-3278
--
signature.asc -> http://www.thelounge.net/signature.asc.what.htm
--
()  campaña lazo ascii  |  por favor, enviar correo ascii
/\  www.asciiribbon.org |  por favor, enviar adjuntos en formato libre


Re: Sorting Multidimentional Arrays

2016-10-01 Thread Larry Wall
On Sat, Oct 01, 2016 at 07:57:34PM +0200, mimosinnet wrote:
: @opposite = @opposite.sort({@$^a[3]});

I'd probably write that as:

@opposite .= sort: { $^a[3] }

or maybe just

@opposite .= sort( *[3] );

Larry


Sorting Multidimentional Arrays

2016-10-01 Thread mimosinnet
I have been searching on how to sort multidimensional arrays. The 
following code works and sorts the fourth column of the array:


---
#!/usr/bin/env perl6
# sort multidimensional array 


my @opposite = (
<8976 ABD AB11 6LX NJ >,
<8860 PLN AB12 4JS NO >,
<8905 DYC AB21 7EQ NJ >,
<8964 STN AB39 2NE NO >,
);

for @opposite -> $line { say $line; }
say "-" x 22;
@opposite = @opposite.sort({@$^a[3]});

for @opposite -> $line { say $line; }
---

I have adapted this from: 
http://www.wellho.net/resources/ex.php?item=p600/mapper


I wanted to ask about the syntax, buy I have understood it while 
writing the message ;) :D 


Leve the code just in case is useful for somebody else.

Cheers!

--
(≧∇≦) Mimosinnet (Linux User: #463211)