Calling Diff on Arrays

R

Robert Love

I can read in two text files into arrays of lines, manipulate and sort
the contents. I then want to pass the arrays to diff and manipulate and
print the results of the diff. I have it working using temporary files
that I write the arrays into. My question is how do I do this directly,
without writing to temporary files?

What I have now looks like:

@results = `diff tmp1 tmp2`;

I have read FAQ 4.xx and that is NOT what I want. All tips & advice
appreciated.
 
R

rlove

Kevin said:
Algorithm::Diff

Thanks but that doesn't seem to be part of my perl installation. I'm
working on a set of RH 7.2 linux machines that I don't adminster. I
can't talk the pointy hair bosses into upgrading either.

Just installing this local to my machine wouldn't help others I want to
run the tool.

So, I repeat the question. Is there a way to call diff directly
without writing the contents of my @rrays to files first?
 
A

A. Sinan Unur

(e-mail address removed) wrote in
Thanks but that doesn't seem to be part of my perl installation. I'm
working on a set of RH 7.2 linux machines that I don't adminster. I
can't talk the pointy hair bosses into upgrading either.

Just installing this local to my machine wouldn't help others I want
to run the tool.

perldoc -q lib

If the machines are identical, all you have to do is to install in a
subdirectory to which you have access, and then add the appropriate

use lib 'path to my lib';

statement to your script, then copy to other machines.
So, I repeat the question. Is there a way to call diff directly
without writing the contents of my @rrays to files first?

It probably depends on the diff program you are using. Reading man diff
on my Cygwin system points out a possible solution:

FILES are `FILE1 FILE2' or `DIR1 DIR2' or `DIR FILE...' or
`FILE... DIR'. If --from-file or --to-file is given, there are no
restrictions on FILES. If a FILE is `-', read standard input. Exit
status is 0 if inputs are the same, 1 if different, 2 if trouble.

Sinan
 
J

James E Keenan

Robert said:
I can read in two text files into arrays of lines, manipulate and sort
the contents. I then want to pass the arrays to diff and manipulate and
print the results of the diff. I have it working using temporary files
that I write the arrays into. My question is how do I do this directly,
without writing to temporary files?

You state that you "manipulate" the contents in the temp files and then
"manipulate" the arrays. My hunch is that the solution depends on what
you mean by "manipulate" in each context. Algorithm::Diff, as others
have suggested, may be of use here. For determining the differences
between two or more sets, my CPAN distribution List::Compare may be useful.

jimk
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top