Help for this page

Select Code to Download


  1. or download this
    sub natural_sort {
        return @_ if @_ < 2;
    ...
        };
        return @_[@words.sort.map({@(split(' ',$^_))[*-1]})];
    }
    
  2. or download this
    sub natural_cmp {
        my ($one, $two) = @_[0,1].map({ .=subst(/(\d+)/, 
          -> $/{ sprintf( "%s%c%s", 0, $0.chars, $0) }, :g).lc });
        return ($one cmp $two);
    }
    
  3. or download this
    sub natural_cmp ($a, $b) {
        my ($first, $second) = ($a, $b);
    ...
          -> $/{ sprintf( "%s%c%s", 0, $0.chars, $0) }, :g).lc });
        return ($one cmp $two);
    }
    
  4. or download this
    use v6;
        # perl 6. automatic strict, warnings and autodie
    ...
          -> $/{ sprintf( "%s%c%s", 0, $0.chars, $0) }, :g).lc });
        return ($one cmp $two);
    }