Update 2: demerphq reminded me that his code returns the list. My code has been updated to do so, and comes in at
106:
# this is LEXICAL sorting
#2345678901234567890123456789012345678901234567890123
sub JAPHY {
sort{(*-,*+)=map[/^\s*(0|-?[1-9]\d{0,8})(.*)$/],$a,$b
;@-?@+?$-[0]-$+[0]||$-[1]cmp$+[1]:-1:@+?1:$a cmp$b}@_
}
Update: new code under 100, at
98... oh, notice how I'm leaving that space in between
$a and
cmp? If it's legal for me to put a newline there and not have it count, let me know.
#234567890123456789012345678901234567890123456789
sub JAPHY {
(*-,*+)=map[/^\s*(0|-?[1-9]\d{0,8})(.*)$/],$a,$b;
@-?@+?$-[0]-$+[0]||$-[1]cmp$+[1]:-1:@+?1:$a cmp$b
}
Here's my sorting function, with a healthy count of
107:
#2345678901234567890123456789012345678901234567890123456
sub JAPHY {
my($A,$B)=map[/^\s*(0|-?[1-9]\d{0,8})(.*)$/],$a,$b;
@$A?@$B?$$A[0]-$$B[0]||$$A[1]cmp$$B[1]:-1:@$B?1:$a cmp$b
}
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker, who could use a job
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.