in reply to ppk
First red flag:
This code will get an incorrect $1 if the regex doesn't match. Never never Never look at $1 unless you've also tested the match.$b =~m/^\s*\w+\s+(\d+)\s+/o; my $b_pid = $1;
Oh, and that applies a few lines later too. At least you're consistently wrong.
Second red flag:
Never never never use kill -9 on a process, unless that process has resisted prior attempts to die via kill 1, 2, and 15.my @args = ("kill", "-9", $2);
First yellow flag, back to the earlier code snippet:
What's the /o doing there? {insert cricket chirp sound effects} Right, nothing. Doesn't hurt it, but it absolutely doesn't help it either. In fact, you should remove it universally in this program (I just noticed it earlier too).m/^\s*\w+\s+(\d+)\s+/o
Second yellow flag... that sort screams for a Schwartzian Transform.
Third yellow flag: Perl has a kill function. Why not use it instead of system'ing out?
Conclusion: other than the bit about the Schwartzian Transform, the knowledge you are missing is contained within Learning Perl, which suggests that you read that book very soon.
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: ppk
by jplindstrom (Monsignor) on Apr 19, 2005 at 11:44 UTC | |
by jplindstrom (Monsignor) on Apr 19, 2005 at 18:15 UTC | |