in reply to Best way to compare my data?

The following uses Algorithm::Diff to do the heavy lifting:

use strict; use warnings; use Algorithm::Diff; my @routes; local $/ = "\n\n"; push @routes, $_ while $_ = <DATA>; chomp @routes; @routes = map {[split "\n"]} @routes; my @reference = @{shift @routes}; my $lenChanges = 0; my $hopChanges = 0; for my $route (@routes) { my @diffs = Algorithm::Diff::diff(\@reference, \@$route); next if !@diffs; @reference != @$route ? ++$lenChanges : ++$hopChanges; } print "Length changes: $lenChanges\n"; print "Hop changes: $hopChanges\n"; __DATA__ 13,4.69.137.70 14,4.69.134.70 15,4.69.134.113 16,4.69.135.185 17,4.69.134.246 18,4.68.18.75 19,4.59.0.10 20,124.211.34.129 21,203.181.100.61 22,118.155.197.140 23,124.211.10.66 24,163.139.130.138 25,163.139.124.57 26,202.215.179.1 27,202.215.179.11 13,4.69.137.74 14,4.69.134.70 15,4.69.134.113 16,4.69.135.185 17,4.69.134.246 18,4.68.18.11 19,4.59.0.10 20,124.211.34.121 21,203.181.100.61 22,118.155.197.140 23,124.211.10.66 24,163.139.130.138 25,163.139.124.57 26,202.215.179.1 27,202.215.179.11 13,4.69.137.70 14,4.69.134.78 15,4.69.134.125 16,4.69.135.185 17,4.69.134.250 18,4.68.18.139 19,4.59.0.10 20,124.211.34.121 21,203.181.100.189 22,118.155.197.140 23,124.211.10.66 24,163.139.130.138 25,163.139.124.57 26,202.215.179.1 27,202.215.179.11 13,4.69.137.74 14,4.69.134.70 15,4.69.134.113 16,4.69.135.185 17,4.69.134.246 18,4.68.18.11 19,4.59.0.10 20,124.211.10.120 20,124.211.26.120 21,203.181.100.61 22,118.155.197.140 23,124.211.10.66 24,163.139.130.138 25,163.139.124.57 26,202.215.179.1 27,202.215.179.11

Prints:

Length changes: 1 Hop changes: 2

Note too the use of the $/ record separator special variable to ease the parsing of the file into records.


True laziness is hard work

Replies are listed 'Best First'.
Re^2: Best way to compare my data?
by Lavezzi (Initiate) on Apr 01, 2010 at 22:39 UTC

    Just wanted to say that I very much appreciate all of the help that has been given to me in this thread.

    The reason I haven't replied is that I don't have the time to look at this project at the moment as I have more urgent work to look at in the mean time! So thanks again!