in reply to Re: file comparison
in thread file comparison

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.

Replies are listed 'Best First'.
Re^3: file comparison
by ambrus (Abbot) on Aug 25, 2009 at 10:29 UTC

    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.