Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Golf: reverse sort /etc/passwd by UID

by Tommy (Chaplain)
on Feb 05, 2013 at 20:26 UTC ( #1017274=note: print w/ replies, xml ) Need Help??


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

No, no. It does work (tested and confirmed). See my reply to thundergnat.

NOTE- remember you have to omit the typos though, as I already pointed out. So far, the winner remains:

UPDATE: thundergnat is right that the code below DOESN'T work as intended

perl -e 'print reverse sort{/(:\d+:)/<=>/(:\d+:)/}<>' /etc/passwd

Tommy
A mistake can be valuable or costly, depending on how faithfully you pursue correction


Comment on Re^4: Golf: reverse sort /etc/passwd by UID
Download Code
Re^5: Golf: reverse sort /etc/passwd by UID
by thundergnat (Deacon) on Feb 05, 2013 at 20:40 UTC

    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:
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1017274]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2014-07-29 13:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (217 votes), past polls