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

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

by jwkrahn (Monsignor)
on Feb 05, 2013 at 20:27 UTC ( #1017276=note: print w/replies, xml ) Need Help??


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

Does this work?

perl -E"say reverse sort{/(:\d+:)/<=>/(:\d+:)/}<>" /etc/passwd

No, it does not work.

In the sort compare function the current records are in $a and $b but you are not accessing the current record in your example.

The comparison operator <=> puts its operands into scalar context and the match operator in scalar context returns TRUE or FALSE so you are not comparing the contents of the capturing parentheses.

Replies are listed 'Best First'.
Re^3: Golf: reverse sort /etc/passwd by UID
by Tommy (Chaplain) on Feb 05, 2013 at 20:36 UTC

    It works, using the exact input I specified (as well as my /etc/passwd file...

    UPDATE: see my post about me being wrong...

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

      Notice that your input is already "sorted". All that one liner does is reverse it.

        Noted. Re-reading perldoc -f sort reveals that the sort of "magic" I thought I was seeing wasn't the case. $a and $b are package globals explicitly passed by Perl itself to the sort block (or subroutine of your definition). It's not a bare leftside-rightside comparison of whatever expressions you may provide. You have to explicitly use the $a and $b package global symbols, and $_ isn't $a/$b. Them's the rules.

        I do indeed stand corrected.

        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
Node Status?
node history
Node Type: note [id://1017276]
help
Chatterbox?
[stevieb]: yeah, so the wiringPi library appears to be missing/injecting incorrect defined variables into I2C calls, and it's all over the map. I'm going to have to revisit and use something else, write something else, or scrutinize the code and fix

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2017-06-23 00:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (532 votes). Check out past polls.