in reply to Re^9: Sorting text-number values
in thread Sorting text-number values

Sadly I have just realised that this solution gives multiple entries for data which has values which are the same.

I appreciate it would be simple to go through the sorted array and removed any duplicates.

However, can this also be done with a modification to the 'pack' statement or my some other means?

Replies are listed 'Best First'.
Re^11: Sorting text-number values
by poj (Abbot) on Nov 30, 2016 at 13:33 UTC
    Try
    #!perl use strict; my %tmp=(); while (<DATA>){ chomp; if ( /(.*\D)?(\d+)$/ ){; my $key = pack "A50N",$1,$2; $tmp{$key} = $_; } else { warn "Data format error $_"; } } my @sorted = map { $tmp{$_} } sort keys %tmp; print "$_\n" for @sorted; __DATA__ 123 blank_5_str_1 blank_6_str_10 blank_5_str_1 blank_6_str_12 blank_5_str_13 blank_6_str_14 blank_5_str_2 blank_5_str_31 blank_5_str_401 blank_5_str_9 blank_5_str_6 dlank_5_str_8 clank_5_str_7 blank_5_str_9 98
    poj
      Thanks - that did the job.