Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by choroba (Cardinal)
on Feb 06, 2013 at 15:29 UTC ( [id://1017456]=note: print w/replies, xml ) Need Help??


in reply to Golf: reverse sort /etc/passwd by UID

Only suitable for a terminal, not to be redirected to a file:
# 1 2 3 4 # 12345678901234567890123456789012345678901234 perl -e 'print sort map 9/(1+(split/:/)[2])."\r$_",<>' /etc/passwd
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Golf: reverse sort /etc/passwd by UID
by tobyink (Canon) on Feb 06, 2013 at 22:11 UTC

    Nice, but one of the lines in my /etc/passwd file comes out as:

    1.52590218966964e-05\rnobody:x:65534:65534:nobody:/nonexistent:/bin/sh

    And thus gets sorted after root.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
      OK, just change 1/ to 9/ (or 8 or 7). Updated.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^2: Golf: reverse sort /etc/passwd by UID
by MidLifeXis (Monsignor) on Feb 06, 2013 at 18:02 UTC

      I'm not clear on how it sorts on a field in the text while at the same time appending the text to the field which is sorted. What am I missing here?

      Tommy
      A mistake can be valuable or costly, depending on how faithfully you pursue correction
        at the same time
        Nothing is happening at the same time. The steps shown by MidLifeXis are ordered (maybe <ol> would have been better than <ul>). First, the text is concatenated, then it is sorted.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^2: Golf: reverse sort /etc/passwd by UID
by Tommy (Chaplain) on Feb 06, 2013 at 17:24 UTC

    Good gosh, can't even decipher that. Sorting the output of a map applying a mathematical expression to the list of lines on STDIN... but how do you discard the text it generated here --> (1+(split/:/)[2])<-- ??

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-03-19 02:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found