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

Also, I do need to understand where the data is stored or how to store the sorted data in an array.

Just assign to an array!

my @sorted = map { substr $_, 54 } sort map { do { no warnings qw{ uninitialized }; pack qq{A${width}NA*}, m{(.*\D)?(\d+)$}, $_; } } @data;

Simples!

Cheers,

JohnGG

Replies are listed 'Best First'.
Re^10: Sorting text-number values
by merrymonk (Hermit) on Nov 30, 2016 at 12:05 UTC
    I thought it might be, it was just finding it out which was the problem!
Re^10: Sorting text-number values
by merrymonk (Hermit) on Nov 30, 2016 at 12:29 UTC
    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?

      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.