Hi
I am trying to do a sort on a 2d array in perl. I want to sort on the second column (i.e. indexed by 1) and sort the whole array of arrays alphabetically by the string in [1]. So now its like this: (elements split on space)
A fe00m 50 40 <epoch time> C 41 <epoch time>
A fe06m 50 28 <epoch time> C 60 <epoch time>
I want this (just sorting on one column)
A fe00m 50 40 <epoch time> C 41 <epoch time>
A fe06m 50 28 <epoch time> C 60 <epoch time>
A fe14m 50 11 <epoch time> C 55 <epoch time>
This is the code I am trying to use:
@thresharray = sort { $a->[1] cmp $b->[1] } @thresharray;
Any ideas why it seems to not do anything?
Thanks
I am trying to do a sort on a 2d array in perl. I want to sort on the second column (i.e. indexed by 1) and sort the whole array of arrays alphabetically by the string in [1]. So now its like this: (elements split on space)
A fe00m 50 40 <epoch time> C 41 <epoch time>
A fe06m 50 28 <epoch time> C 60 <epoch time>
I want this (just sorting on one column)
A fe00m 50 40 <epoch time> C 41 <epoch time>
A fe06m 50 28 <epoch time> C 60 <epoch time>
A fe14m 50 11 <epoch time> C 55 <epoch time>
This is the code I am trying to use:
@thresharray = sort { $a->[1] cmp $b->[1] } @thresharray;
Any ideas why it seems to not do anything?
Thanks
Last edited: