Help for this page

Select Code to Download


  1. or download this
    my @sorted =
       map  { $_->[0] }
       sort { $a->[1] cmp $b->[1] } # or <=>, or $b before $a
       map  { [$_, f($_)] }
       @unsorted;
    
  2. or download this
    # the first map does this
    qw(8 11 9 4 3) --> (
    ...
      [ 4, "vi"],
      [ 3, "iii"],
    )
    
  3. or download this
    # the sort does this:
    (
    ...
      [ 8, "viii"],
      [11, "xi"],
    )
    
  4. or download this
    (
      [ 3, "iii"],
    ...
      [ 8, "viii"],
      [11, "xi"],
    ) --> qw( 3 9 4 8 11 )
    
  5. or download this
    use strict;
    use warnings;
    ...
    
    __END__ # output shown below
    3 4 9 8 11
    
  6. or download this
    my @sorted = sort { f($a) cmp f($b) } @unsorted;
    
  7. or download this
    *f = sub {
        $::count++;
        END { print "f() called $::count times\n" };
        goto \&Roman::roman;
    };
    
  8. or download this
    use List::Util "shuffle";
    my @unsorted = shuffle(1..100);