in reply to substr sort ??

I know it is not important in this case since @values is so small but on larger arrays a Schwartzian Transform might be in order. This example will take care of cases where the number of digits is not the same.
my @values = ( '123=more digits', '04=critical', '02=informational', '01=unknown', '10=test', '03=warning', '08=foo', ); @values = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [/(\d+)/, $_]} @values; print join "\n", @values; __OUTPUT__ 01=unknown 02=informational 03=warning 04=critical 08=foo 10=test 123=more digits

--

flounder

Replies are listed 'Best First'.
Re:substr sort ??
by kesterkester (Hermit) on Aug 22, 2003 at 14:12 UTC
    Since the input data appear to be delimitted by the "=", using a split to generate the sort key might be more robust:
    #!/usr/bin/perl use warnings; use strict; my @values = ( '123=more digits', '04=critical', '02=informational', '01=unknown', '10=test', '03=warning', '08=foo', ); @values = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ ( split /=/ )[0], $_ ] } @values; print "@values\n";
    output = 01=unknown 02=informational 03=warning 04=critical 08=foo 10=test 123=more digits