You can open a filehandle on a piped command and you can also use Perl's built-in grep to do what sed does in your code. Here's an example applied to a couple of nonsense files.
$ diff dddd eeee 2c2 < werfef --- > werftef 7c7 < esdd --- > es4dd $ $ diff dddd eeee | sed -re '/^[><]/d' 2c2 --- 7c7 --- $
The script to do the same job.
use strict; use warnings; my $file1 = q{dddd}; my $file2 = q{eeee}; my @diffs = do{ open my $diffFH, q{-|}, qq{diff $file1 $file2} or die qq{fork: diff $file1 $file2: $!\n}; grep ! m{^[><]}, <$diffFH>; }; print for @diffs;
The output, which is identical to that produced by diff and sed on the comand line.
$ ./spw765446 2c2 --- 7c7 --- $
I hope this is useful.
Cheers,
JohnGG
In reply to Re: using system() and putting results into an array
by johngg
in thread using system() and putting results into an array
by lasagnashoe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |