Help for this page

Select Code to Download


  1. or download this
    sub natural_cmp ($a, $b) {
        my ($one, $two) = ($a, $b).map(*.subst(/(\d+)/, 
          -> $/{ sprintf( "%s%c%s", 0, $0.chars, $0) }, :g).lc);
        return $one cmp $two;
    }
    
  2. or download this
    sub natural_cmp ($a is copy, $b is copy) {
       return $a.subst(/(\d+)/, -> $/{ sprintf( "%s%c%s", 0, $0.chars, $0)
    + }, :g).lc
       cmp $b.subst(/(\d+)/, -> $/{ sprintf( "%s%c%s", 0, $0.chars, $0) },
    + :g).lc;
    }