Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: multi column multi file comparison

by tospo (Hermit)
on May 21, 2011 at 12:11 UTC ( #906060=note: print w/replies, xml ) Need Help??

in reply to multi column multi file comparison

The way to get started with something like this is to write an algorithm for solving the problem in plain English and then try to break the problem into chunks that you can tackle one by one.
In this case, your first chunk to solve would be how to read all the data from the master file into a format that allows you to compare each entry from the other files with the master file. What you want for this is a Hash of Arrays like so:
my %master = ( Alex => [ [3,44], [124,175] ], Barry => [ [2,44] ], # more data here # );
Here, I associate every name with a list of ranges stored as references to arrays. Each range in turn is also a reference to an Array of two elements, the start and end of the range. Of course you could also store the range as a string. wouldn't really make much of a difference in this case.
Now you can access data for a person by name and iterate over all their ranges like so:
my $some_name = 'Alex'; foreach my $range ( @{$master{$some_name}} ){ my ($start, $end) = @$range; print "$start, $end\n"; }
What you need to figure out now is how to read your master into the %master hash and how to get $some_name and how to compare the ranges. Have a go at that and let us know if you run into problems.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://906060]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2018-01-23 18:18 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (251 votes). Check out past polls.