
BillKSmith
Veteran
Jul 12, 2010, 6:33 AM
Post #2 of 2
(270 views)
|
Extract the number with a regular expression See perldoc -q sort for Schwartzian Transform
use strict; use warnings; my @ace_data = ( 'abc-123', 'abc-def-345.', 'abc-ghi-.678', ); my $GET_NUMBER = '\A # Start of record (?:[a-z]{3}-){1,2} # hypen separted groups of three (\d+\.\d* | # d[ddd][][dddd] \.?\d+) # []d[ddd] \Z # End of record' ; my @sorted_data = map $_->[1], sort {$a->[0] <=> $b->[0]} map [(my $number) = /$GET_NUMBER/xms, $_], @ace_data ; foreach my $record (@sorted_data) { print $record, "\n"; } Results: abc-ghi-.678 abc-123 abc-def-345. For this example, the RE only needs the two lines related to numbers. I am not clear what your data really is like Good Luck, Bill
|