in reply to schwartzian transform problem - Solved

Instead of using complex code to make sort efficient, use Sort::Key which handles that for you without the messy code.

use File::Slurper qw( read_text ); use Sort::Key qw( rikeysort ); print rikeysort { ( /(\d+)%/ )[0] } split /^(?=>>> )/m, read_text( 'try3.txt' );

(Also note the more reliable split pattern.)

Features:


  1. The builtin-sort on modern versions of Perl is a stable sort. And this means the provided ST solution is a stable sort on modern version of Perl. But the provided GRT solution isn't a stable sort.

Replies are listed 'Best First'.
Re^2: schwartzian transform problem
by etj (Priest) on Mar 01, 2025 at 10:57 UTC
    This is a situation where there's no substitute for measuring, e.g. with Benchmark.
      I ran tests on the GRT and ST on 90_000 lines and they both ran in less than one second. The GRT ran in 1/5 second and the ST ran in 1/15 second
        Given the parent node of your node, this might sound repetitive, but that's exactly why modules like Benchmark exist.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]