Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Perl Monk, Perl Meditation
 
PerlMonks  

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

by choroba (Abbot)
on Feb 06, 2013 at 15:29 UTC ( #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
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Golf: reverse sort /etc/passwd by UID
Download Code
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
Re^2: Golf: reverse sort /etc/passwd by UID
by MidLifeXis (Prior) 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 tobyink (Abbot) 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.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (13)
As of 2014-04-18 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (469 votes), past polls