Here's a way to do it using split within a Schwartzian Transform:
#!/usr/bin/perl use strict; use warnings; my @data = <DATA>; # Schwartzian Transform print map { $_->[0] } sort { $a->[1][1] <=> $b->[1][1] or $a->[1][0] <=> $b->[1][0] } map { [ $_, [ (split m/,/, $_, 3)[0, 1] ] ] } @data; __DATA__ 1,64,1.4.5,1.4.6,44642850,44642850,0,27348,10028,59188,1488095,761904. +64 1,128,1.4.5,1.4.6,25337850,25337850,0,19236,10276,28196,844595,864865. +28 1,256,1.4.5,1.4.6,13489200,13489200,0,17792,11372,17832,449640,920862. +72 1,512,1.4.5,1.4.6,6996270,6996270,0,18084,16744,19124,233209,955224.06 +4 1,1024,1.4.5,1.4.6,3557880,3557880,0,31528,20488,35188,118596,971538.4 +32 2,64,1.4.5,1.4.6,44642850,44642850,0,25828,9548,40128,1488095,761904.6 +4 2,128,1.4.5,1.4.6,25337850,25337850,0,27936,10796,28696,844595,864865. +28 2,256,1.4.5,1.4.6,13489200,13489200,0,12852,10692,13332,449640,920862. +72 2,512,1.4.5,1.4.6,6996270,6996270,0,17184,15904,18844,233209,955224.06 +4 2,1024,1.4.5,1.4.6,3557880,3557880,0,34068,17948,36628,118596,971538.4 +32
UPDATE: If you prefer regular expression pattern matching to split-ting in this case, just replace the initial map with this:
map { [ $_, [ m/^(\d+),(\d+)/ ] ] }
In reply to Re: numeric sort on substring
by Jim
in thread numeric sort on substring
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |