using grep and diff

C

Chris

use Shell("grep", "diff");
my $item=diff("file1 file2","");
my $other=grep($item,""^[0-9]"");

How can I get this to work beacuse the grep need the "" around the ^[0-9] or
is it possible to put the diff and grep into a shell script and then have
perl run the script? if so how would it be done.
 
A

A. Sinan Unur

use Shell("grep", "diff");

Are you still insisting on this?

perldoc Shell

perldoc -f system
my $item=diff("file1 file2","");
my $other=grep($item,""^[0-9]"");

How can I get this to work beacuse the grep need the "" around the
^[0-9] or is it possible to put the diff and grep into a shell script
and then have perl run the script? if so how would it be done.

perldoc perlop

See "Quote and Quote-like Operators".

Sinan
 
J

Jürgen Exner

Chris said:
use Shell("grep", "diff");
my $item=diff("file1 file2","");
my $other=grep($item,""^[0-9]"");

How can I get this to work beacuse the grep need the "" around the
^[0-9]

Is there anything wrong with a simple

my @foo = `diff file1 file2`;

and then using Perl's own grep() instead of forking out an external process?
or is it possible to put the diff and grep into a shell script
and then have perl run the script? if so how would it be done.

Just the same way you would run any other external program from Perl: by
using system(), backticks, or open() with a pipe.

jue
 
C

Christopher Nehren

use Shell("grep", "diff");
my $item=diff("file1 file2","");
my $other=grep($item,""^[0-9]"");

Wow ... shelling out to do text processing in Perl! Seriously. Get some
modules and learn about Perl's regex engine (which is infinitely better
than anything your grep can ever provide, by the way[1]) and the
Algorithm::Diff module.

[1]: Unless it was written in Perl, of course ...
http://search.cpan.org/src/CWEST/ppt-0.14/bin/grep

Best Regards,
Christopher Nehren
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top