Calling Diff on Arrays

Discussion in 'Perl Misc' started by Robert Love, Aug 29, 2005.

  1. Robert Love

    Robert Love Guest

    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.
     
    Robert Love, Aug 29, 2005
    #1
    1. Advertising

  2. Robert Love

    Guest

    Kevin Michael Vail wrote:
    > In article <>,
    > Robert Love <> wrote:
    >
    > > 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.

    >
    > 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?
     
    , Aug 29, 2005
    #2
    1. Advertising

  3. wrote in
    news::

    >
    > Kevin Michael Vail wrote:
    >> In article <>,
    >> Robert Love <> wrote:
    >>
    >> > 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.

    >>
    >> 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.


    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

    --
    A. Sinan Unur <>
    (reverse each component and remove .invalid for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
     
    A. Sinan Unur, Aug 29, 2005
    #3
  4. Robert Love wrote:
    > 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
     
    James E Keenan, Aug 30, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cyril Vi?ville

    diff Process under diff users

    Cyril Vi?ville, Jun 29, 2004, in forum: Perl
    Replies:
    1
    Views:
    534
    Joe Smith
    Jun 29, 2004
  2. Berrucho
    Replies:
    2
    Views:
    682
    Infant Newbie
    Dec 5, 2003
  3. A Traveler

    Diff CSS styles for diff INPUT TYPE='s?

    A Traveler, Aug 31, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,981
    Steve Fulton
    Aug 31, 2004
  4. Philipp
    Replies:
    21
    Views:
    1,190
    Philipp
    Jan 20, 2009
  5. Austin Ziegler

    [ANN] Diff::LCS 1.1.0, Diff::LCS 1.0.4

    Austin Ziegler, Aug 8, 2004, in forum: Ruby
    Replies:
    3
    Views:
    214
    Austin Ziegler
    Aug 9, 2004
Loading...

Share This Page