in reply to file comparison

You could look at Algorithm::Diff or its child Text::Diff for diffing files or sets of outputs. What is the eventual goal of the diffing?

Replies are listed 'Best First'.
Re^2: file comparison
by sqspat (Acolyte) on Aug 25, 2009 at 09:58 UTC
    Thanks for your reply. I am wanting to verify that what is returned from various commands on the box does not change when the code changes.. i.e. I want to make sure the same response to the commands are obtained when I install new code .... it is part of some automated regression tests I am scripting.

      Oh, in that case just compare the outputs with the cmp program if the outputs are written to files (eg. system("diff", "-s", "--", $filename1, $filename2) returns true if the files are different).

      If you're sure you want the outputs in arrays, compare them with like join("", @output1) eq join("", @output2) if the lines in the arrays still have the trailing newlines or pack("(J/a)*", @output1) eq pack("(J/a)*", @output2) if you're not sure what the delimiters are or @output1 == @output2 and !grep { $output1[$_] ne $output2[$_] } 0 .. @output1 - 1 if you don't want to waste memory.

        Oh, in that case just compare the outputs with the cmp program if the outputs are written to files (eg. system("diff", "-s", "--", $filename1, $filename2) returns true if the files are different).

        Better, use File::Compare, which is part of the standard dist.