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

Without the addtional print nothing.

Replies are listed 'Best First'.
Re^5: Sorting text-number values
by Corion (Patriarch) on Nov 30, 2016 at 10:16 UTC

    That's really weird, because for me, the program outputs the following:

    #!perl -w use strict; use 5.010; my @data = qw{ this_5_string_12 some_12_garbage_23 this_5_string_8 17 this_5_string_23 some_12_garbage_6 102 this_5_string_19 5 this_5_string_101 }; my $width = 50; say for map { substr $_, 54 } sort map { do { no warnings qw{ uninitialized }; pack qq{A${width}NA*}, m{(.*\D)?(\d+)$}, $_; } } @data;
    Output:
    5 17 102 some_12_garbage_6 some_12_garbage_23 this_5_string_8 this_5_string_12 this_5_string_19 this_5_string_23 this_5_string_101
      If I use exactly your Perl, I get the output.

      If I ‘hash’ out your ‘use 5.010;’ - I get the following error message on the MSDOS screen

      Bareword "say" not allowed while "strict subs" in use at ………..amonk_f_sort.pz line 28.

      Using

      use strict; print "perl version $^V\n";
      and the output is perl version v5.20.2

      Therefore it seems it is something to do with the version of Perl being used.

      It would be good to know how to change your Perl so that it works using 'use strict;" and with my current version of Perl (and I would like to know where the sorted data is stored or how I can store it in an array).

        If I ‘hash’ out your ‘use 5.010;’ - I get (... a syntax error)

        So, don't do that then. Leave the working line in place.

        Why do you comment out the use 5.010;?

        The code as posted by me works as is with Perl 5.22 and likely every version of Perl between 5.10 and 5.24.

        If you want to avoid say, read say and then reimplement say using print.