http://www.perlmonks.org?node_id=1017281


in reply to Re^4: Golf: reverse sort /etc/passwd by UID
in thread Golf: reverse sort /etc/passwd by UID

No, no. It doesn't work (tested and confirmed).

The sort block operates on the global variables $a and $b. A match without an explicit variable operates on $_. There is nothing mapping $a and $b to $_ there, so the sort block is just comparing 0 to 0 and leaving the order alone. The fact that /etc/password is in a "sorted" order makes it SEEM like it is working... but it isn't.

print reverse sort{/(:\d+:)/<=>/(:\d+:)/}<DATA>; __DATA__ aaa:5: bbb:3: ccc:1: ddd:7: eee:8:
eee:8:
ddd:7:
ccc:1:
bbb:3:
aaa:5: