in reply to Is it possible to make reference to substrings and sort them?
Using chop could be another way to go.
$ perl -Mstrict -Mwarnings -E ' say join q{}, map { substr $_, -1 } sort sub { my $s = shift; my @r; push @r, do { $s = chop( $s ) . $s; $s; } for 1 .. length $s; return @r; }->( q{BANA$} );' ANB$A $
I think I read somewhere that chop is fast so it might be worth benchmarking.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is it possible to make reference to substrings and sort them?
by AnomalousMonk (Archbishop) on Mar 22, 2015 at 19:19 UTC |