in reply to obtaining pid's in Unix environment
open(PS, "ps -ef |") or die "Problem invoking 'ps': $!\n"; while (<PS>) { next unless /$version/ && /online/; my($pid) = (split)[2]; print "pid $pid\n"; } close(PS);
Cheers,
Matt
P.S. If you want to access the value of $pid outside of the while loop, drop the 'my' but keep the parens, but that will break if there's more than one match:
while (<PS>) { next unless /$version/ && /online/; ($pid) = (split)[2]; } print "pid $pid\n";
|
|---|