jiashiun has asked for the wisdom of the Perl Monks concerning the following question:
Can anyone explain the codes below?
# Code1 @s = sort mycriteria @a; sub mycriteria { my($aa) = $a =~ /(\d+)/; my($bb) = $b =~ /(\d+)/; sin($aa) <=> sin($bb) || $aa*$aa <=> $bb*$bb; }
# Code2 @s = sort {($a =~ /(\d+)/)[0] <=> ($b =~ /(\d+)/)[0] || uc($a) cmp uc( +$b)} @a;
How the regular expressions function in the code above??
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Questions on sort
by ikegami (Patriarch) on Aug 16, 2011 at 05:46 UTC | |
by jiashiun (Initiate) on Aug 16, 2011 at 06:09 UTC | |
by jwkrahn (Abbot) on Aug 16, 2011 at 06:56 UTC | |
by locked_user sundialsvc4 (Abbot) on Aug 16, 2011 at 12:23 UTC | |
by ikegami (Patriarch) on Aug 16, 2011 at 06:49 UTC | |
by Anonymous Monk on Aug 16, 2011 at 06:27 UTC | |
|
Re: Questions on sort
by jiashiun (Initiate) on Aug 20, 2011 at 09:23 UTC |