Angharad has asked for the wisdom of the Perl Monks concerning the following question:
...etc1.10.10 1.10.1040 1.10.150 1.10.220
and another that looks like this (FILE2)
...etc1.10.10.640 1.10.10.650 1.10.10.660 1.10.1040.20 1.10.150.290 1.10.150.300 1.10.150.310 1.10.220.80
I'm wanting to match the first three numbers from the 4 number strings in FILE2 (each number being separated by a '.') with the corresponding three number strings in FILE1 and then count how many matches there are.
For example for the three number string 1.10.10 in FILE1 there are 3 matches in FILE2.
I want the output file to look like this:
I've got the following script1.10.10 3 1.10.1040 1 1.10.150 3 1.10.220 1
But its simply not working properly - its not finding all the matches. I've given only example files here - the actual files are much bigger - some matches are recognised but not all. Any pointers in the right direction much appreciated!!!use strict; my $file1 = shift; my $file2 = shift; open(FILE1, $file1) or die "Cant open $file1:$!\n"; open(FILE2, $file2) or die "Cant open $file2:$!\n"; my @file1 =<FILE1>; my @file2 =<FILE2>; #print @file1; #print @file2; for(my $i=0; $i<@file1; $i++) { chop($file1[$i]); #print "F $file1[$i]"; for(my $j=0; $j<@file2; $j++) { chop($file2[$j]); my @array = split(/\./, $file2[$j]); my $cat = "$array[0]" . "." . "$array[1]" . "." . "$array[2]"; if("$file1[$i]" eq "$cat") { print "$file1[$i] $cat\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: help requested with collating data from two files
by ikegami (Patriarch) on Sep 13, 2010 at 21:07 UTC | |
|
Re: help requested with collating data from two files
by kennethk (Abbot) on Sep 13, 2010 at 21:01 UTC | |
by ikegami (Patriarch) on Sep 13, 2010 at 21:10 UTC | |
|
Re: help requested with collating data from two files
by dasgar (Priest) on Sep 13, 2010 at 21:10 UTC | |
by planetscape (Chancellor) on Sep 14, 2010 at 03:29 UTC | |
|
Re: help requested with collating data from two files
by Utilitarian (Vicar) on Sep 14, 2010 at 08:37 UTC | |
|
Re: help requested with collating data from two files
by Angharad (Pilgrim) on Sep 13, 2010 at 21:15 UTC |