If you want a Perl number, just go straight to the number without eval. Save the parts you are extracting and use them as a cache key:
use 5.010; while( <DATA> ) { chomp; m/ (?: (?<coefficient> \d+ (?:\.\d+)? ) \s+ )? (?<base> (\d+) ) \^ (?<exponent> -?\d+ ) /x; push @numbers, [ ( $+{coefficient} // 1 ), $+{exponent}, $_ ]; } my @sorted = sort { $a->[1] <=> $b->[1] || $a->[0] <=> $b->[0] } @numbers; foreach my $number ( @sorted ) { print "$number->[-1]\n"; } __DATA__ 10^-92 2 10^-14 10^-105 3 10^-20
You can weld this before the Schwartz transform:
use 5.010; print map { $_->[-1] } sort { $a->[1] <=> $b->[1] || $a->[0] <=> $b->[0] } map { m/ (?:(?<c> \d+ (?:\.\d+)? ) \s+ )? # coefficient (?<b> (\d+) ) # base \^ (?<e> -?\d+ ) # exponent /x; [ ( $+{c} // 1 ), $+{e}, $_ ]; } <DATA>; __DATA__ 10^-92 2 10^-14 10^-105 3 10^-20
source share