Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: How to sort output?

by BrowserUk (Pope)
on Jul 22, 2007 at 07:14 UTC ( #628093=note: print w/replies, xml ) Need Help??

in reply to How to sort output?

This (untested) code should do the trick. It uses a regex to extract the numbers and a GRT (see A brief tutorial on Perl's native sorting facilities.) to make the sort reasonably efficient.

## [ip: 111.222.333.444] is alive 70.05 ms) ## Updated: switched 'N' for 'd'; real data. my @sorted = map { unpack 'x[d] A*', $_ } sort map { my( $time ) = m[([\d.]+) ms)$]; pack 'd A*', $time, $_; } @data;

The regex will need tweaking if the latency can produce numbers in other units. Eg. whole seconds or microseconds instead of milliseconds.

You might need something like:

my( $time, $units ) = m[([\d.]+) (ms|us|secs)]; my $scaler = $units eq 'us' ? 0.1 : $units eq 'secs' ? 1000 : 1; $time *= $scaler;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://628093]
[davido]: ok, on my ubuntu system getlogin grabs from /proc/self/ loginuid (per strace)
[tye]: disable /proc and then see what it does?
[davido]: then it reads from /etc/passwd to decide who my uid is.
[davido]: sorry, typed that before you asked me to disable proc
[davido]: but you stumped me; don't know how to disable proc.
[tye]: I don't know if you can just dismount, but I thought so.
[davido]: yeah, umount -f isn't powerful enough.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2017-06-23 20:00 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (554 votes). Check out past polls.