in reply to Two files comparasion
Since perl 5.10.x, Perl has a new operator, the smart match operator, ~~ (see this tutorial), which might actually work in your case, and compare line by line. I don't know, I've not used it much, yet. Looking at that tutorial, it looks like it ought to.
There must be other solutions, for if you need it to work on an older perl. For example, take a look at how some Test modules do it, for example, Test::Deep, where you can simply compare arrays for equality, with the function cmp_deeply.
A really simple solution is to load the whole files into two scalars, instead of into arrays, and compare them as strings. Just set $/ to undef and you read the whole file as one line.
That really requires very little change in your code.local $/; #sets to undef for the current scope open(DAT_Source, $Source_data_file) || die("Could not open file!"); $raw_data_source=<DAT_Source>; open(DAT_Expected, $Expected_data_file) || die("Could not open file!") +; $raw_data_Expected=<DAT_Expected>; if ($raw_data_source eq $raw_data_Expected) { print "DATA MATCHED!"; } else { print "DATA NOT MATCHED!"; }
That's one of the things I really love about Perl: you can often completely change how a piece of code works, by just changing a few thingies here and there.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Two files comparasion
by massa (Hermit) on Aug 01, 2008 at 10:03 UTC | |
by moritz (Cardinal) on Aug 01, 2008 at 10:11 UTC |