Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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.


Comment on Re: multi column multi file comparison
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://906060]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (12)
As of 2014-08-27 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (232 votes), past polls