ashnator has asked for the wisdom of the Perl Monks concerning the following question:
Please help me bcoz its urgent. My files look like this:-sdiff diff gvimdiff etc but no success
File 1:- Harry 21 Jeff 45 Rob 78 Mett 34 Ann 17 Gilli 39 DOn 98 Ben 15 Harry 54 Rose 46 Ness 65 File 2:- 2133 32 45 45 CC Old Harry (D) (28%) 21 + -1 Rob (D) (31%) 78 + -1 Met +t (D) (14%) 34 + -1 5789 78 66 32 DD Young Gilli (D) (10%) 39 + -1 Don (D) (66%) 98 + -1 M +ett (D) (23%) 15 + +1 9027 56 77 29 GG Old Harry (D) (10%) 54 + -1 Rose (D) (%) 46 + -1 Ness + (D) (67%) 65 + 1
I am new to scripting so donno how to approach the problem. I would be obliged to get help from Monks Bravo ... Here is my code but not getting the output yet :(I have to get my results like this:- If suppose Harry, Rob and Met are present 2133 32 45 45 CC Old Harry (D) (28%) 21 + -1 Rob (D) (31%) 78 + -1 Met +t (D) (14%) 34 + -1 3 3 since all the are matching If only Gilli and Don are present in File 1 then 5789 78 66 32 DD Young Gilli (D) (10%) 39 + -1 Don (D) (66%) 98 + -1 + 2 2 since only 2 are matching 9027 56 77 29 GG Old Harry (D) (10%) 54 + -1 1 Since only 1 is matching with File 1
#!/usr/bin/perl -w open(FH, "<File1.txt") || die "Cannot open file"; %href; while( FH> ) { chomp($_); $href{$1} = $2 if $_ =~ /(\S+)\s+(\S+)/; } while (my ($key, $value) = each(%href)) { #print $key. ", ". $value."\n"; } close FH; open(FD, "<File2.txt") || die "Cannot open file"; while(<FD>) { chomp; next unless ( s{ \s+(\w+)\s+\([A-Z]\)\s+\(\d*%\)\s+\d\s+\+ +\s[+-]?\d+}{}xms and exists( $href{$1} )); my $name = $1; print "$name\t\t$href{$name}\n"; #@_=split('\t',$_); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File Intersection problem
by johngg (Canon) on Nov 12, 2008 at 16:39 UTC | |
by ashnator (Sexton) on Nov 13, 2008 at 08:26 UTC | |
by johngg (Canon) on Nov 13, 2008 at 22:41 UTC | |
by brsaravan (Scribe) on Nov 13, 2008 at 11:01 UTC | |
|
Re: File Intersection problem
by gone2015 (Deacon) on Nov 12, 2008 at 16:18 UTC | |
|
Re: File Intersection problem
by toolic (Bishop) on Nov 12, 2008 at 16:22 UTC | |
|
Re: File Intersection problem
by JavaFan (Canon) on Nov 12, 2008 at 16:18 UTC |