in reply to compare data between two files using Perl
For info on how to interpret $key, have a look at the documentation for the $; variable in perldoc perlvar. For special cases you can optimize this code.my %seen; open(B, "brd_sym_pn.txt") or die "..."; while (<B>) { my ($RefDes, $Pnumm, $Pkg_Type) = ...parse these from the line... $seen{$RefDes, $Pnumm, $Pkg_Type} = 1; } close(B); open(S, "sym_text_latest.txt") or die "..."; while (<S>) { my ($RefDes, $Pnumm, $Pkg_Type) = ...parse these from the line... $seen{$Refdes, $Pnumm, $Pkg_Type} += 2; } close(S); while (my ($key, $val) = each %seen) { if ($val == 1) { # $key is in first file but not second } elsif ($val == 2) { # $key is in second file but not first } else { # key is in both files } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: compare data between two files using Perl
by steveb94553 (Initiate) on Jun 16, 2008 at 21:35 UTC | |
by pc88mxer (Vicar) on Jun 18, 2008 at 21:19 UTC | |
|
Re^2: compare data between two files using Perl
by Anonymous Monk on Dec 16, 2008 at 12:14 UTC | |
by svenXY (Deacon) on Dec 16, 2008 at 13:04 UTC | |
by Anonymous Monk on Dec 16, 2008 at 14:18 UTC | |
by Anonymous Monk on Dec 16, 2008 at 14:20 UTC | |
by Anonymous Monk on Dec 16, 2008 at 15:08 UTC |