in reply to sorting mixed alpha_digit keys of a hash?
Now your %data hash has the I, Q, P, and IT fields grouped by the number following them.my %data; for my $k (keys %form) { # assumes all the keys are non-numbers followed by numbers my ($letters, $numbers) = $k =~ /(\D+)(\d+)/; $data{$numbers}{$letter} = $form{$k}; }
If you'd rather just sort the keys in this manner and not produce a whole new data structure, I suggest:
This is a standard Schwartzian Transform.# UPDATE (fixed indices!) my @sorted_keys = map { $_->[0] } sort { $a->[2] <=> $b->[2] or $a->[1] cmp $b->[1] } map { [$_, /(\D+)(\d+)/] } keys %form;
|
|---|