The code you provided seems to have a few syntax errors (e.g.,
/usr/local/bin/perl needs the slashes to be escaped, and the regex beginning with
sh is never terminated), but I've tried to clean it up as well as I could. This program is not equivalent to your Unix grep/awk pipeline, but I've tried to keep the meaning of your Perl code approximately the same.
#!/usr/local/bin/perl
use strict;
use warnings;
open(OF,">outr") || die "File not opening outr: $!\n";
foreach (`ps -ef | grep jones` =~ /[^\n]*\n/g) {
next if m!/usr/local/bin/perl ps1$! or /sh -c ps -ef \| grep jones >
+ outr$/;
print OF;
}
close(OF);
Hopefully this does about what you want. A couple of points about it:
- Backticks are used to capture the output of ps rather than a system with output piped to a file.
- "Jones" is changed to "jones" in the grep, since I think that's what you want.
- The elements of the array in a foreach are automatically aliased to $_, so there's no need to do it manually.
- Similarly, $_ is used by default by regexes and print, so there's no need to specify it there, either.
-- Mike
--
just,my${.02}