[HRPM] Sorting ps list - source code for server and client
Matt Shivers
mshivers11 at home.com
Sat Jan 6 10:38:30 CST 2001
Hello all,
Chris... Thanks a bunch for the ps list sort solution. It worked like a
charm. I only had to modify the line:
return $a[$pid] <=> $b[$pid]; to return
$a[$pid] cmp $b[$pid];
when comparing fields with strings in them.
I reviewed each line to figure out what it did, but I couldn't nail down the
following line:
$copya =~ s/^\s+//; $copyb =~ s/^\s+//;
This binds the pattern to the scalars, but what is it accomplishing? Would
you shed some light on this?
Thanks again,
Matt
P.S. code snippet:
sub pidorder {
my $pid = 0; # index into array
my $copya = $a; my $copyb = $b;
$copya =~ s/^\s+//; $copyb =~ s/^\s+//;
my @a = split(/\s+/,$copya,7); my @b = split(/\s+/,$copyb,7);
if (0) {
my $proca = $a[6]; my $procb = $b[6];
$proca =~ s/\s+/ /g; $procb =~ s/\s+/ /g;
print "comparing '$a[$pid]' to '$b[$pid]' ($proca,$procb)\n";
}
return $a[$pid] <=> $b[$pid];
}
----- Original Message -----
From: <chicks at chicks.net>
To: <norfolk-pm-list at happyfunball.pm.org>
Sent: Sunday, November 26, 2000 1:26 PM
Subject: Re: [HRPM] Sorting ps list - source code for server and client
> On Tue, 21 Nov 2000, Matt Shivers wrote:
> > Warning it's a lot of code...
>
> That's what 'dd' is for. :-)
>
> I've attached my rewrite of Matt's script. There's a longish comment at
> the beginning which contains some minor nits, but the main point was to
> demonstrate creating a custom sort routine and I hope you will find this a
> decent example.
>
> --
> </chris>
>
> "Pinky, you've left the lens cap of your mind on again." - The Brain
>
More information about the Norfolk-pm
mailing list