in reply to Sorting a hash that has mixed-format keys
Here's an example of what hippo was talking about. Note that it only works for positive integers in the range 0 .. 4,294,967,295.
c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dump qw(dd); ;; my @raw_keys = ( '1 12301 A B', '2 4501 A B', '1 12299 E F', '2 4502 C D', '1 12310 A B', '2 4499 C D', '2 15410 A B', ); ;; my $ornament = 'N N'; my $decorate = qq{ $ornament a*}; my $undecorate = qq{x[$ornament] a*}; ;; my @sorted_keys = map unpack($undecorate), sort map pack($decorate, (split ' ', $_, 3)[0,1], $_), @raw_keys ; dd \@sorted_keys; " [ "1 12299 E F", "1 12301 A B", "1 12310 A B", "2 4499 C D", "2 4501 A B", "2 4502 C D", "2 15410 A B", ]
Give a man a fish: <%-{-{-{-<
|
|---|