[Purdue-pm] How to sort one dimension of a 2d array
Joe Kline
gizmo at purdue.edu
Fri Jan 29 07:11:10 PST 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Phillip San Miguel wrote:
> This is probably pretty straight forward, but:
>
> I have a hash of 2d arrays. I want to sort by numerical value across one
> of these dimensions. What would be the syntax for that?
>
> $table{$colors}[0..num_of_traces-1][0..num_data_points-1]
>
> I want sort the values in the first (traces) dimension.
>
> When I try to write the sort syntax my head starts spinning.
>
wouldn't it just be:
@sorted = sort { $a->[0] <=> $b->[0] } @{ $table{$colors} };
?
if you want to sort by data points the index for the sort would be [1],
wouldn't it?
joe
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
Comment: Using GnuPG with Red Hat - http://enigmail.mozdev.org
iD8DBQFLYvqNb0mzA2gRTpkRAqtOAJ9Hg/UDimmea+0Kk9HlIzWzvDxroQCffk9u
fQkzSRbkno7oeymFc553g7s=
=vkRD
-----END PGP SIGNATURE-----
More information about the Purdue-pm
mailing list