fork download
  1. #!/usr/bin/perl
  2.  
  3. # Idiom #290 Sort sublist
  4.  
  5. use feature 'say';
  6.  
  7. @items = qw(0 1 2 3 a b c d e 9 10 11);
  8. ($i,$j) = (4,8);
  9. $c = sub { $b cmp $a }; # sort alpha descending
  10.  
  11. say '# ', join ' ', @items;
  12. @items[$i..$j] = sort $c @items[$i..$j];
  13. say '# ', join ' ', @items;
Success #stdin #stdout 0.01s 5460KB
stdin
Standard input is empty
stdout
# 0 1 2 3 a b c d e 9 10 11
# 0 1 2 3 e d c b a 9 10 11