Hi Monks,
I really hope someone can help me with my issue, I have two text files that I am attempting to compare they are in this structure:
FILE 1
'abc'
'def'
'121'
'xyx'
FILE 2
'def'
'121'
File 3 (output file ideally)
'abc'
'xyz'
however it is showing:
'121'
'abc'
'121'
'xyx'
here is the code I've compiled so far, however the results are not what i desire
use strict;
use warnings;
my $f2 = 'cat_mapping_in_A.txt';
my $f1 = 'cat_mapping_in_B.txt';
my $outfile = '1.txt';
my %results = ();
open FILE1, "$f1" or die "Could not open file: $! \n";
while(my $line = <FILE1>){
$results{$line}=1;
}
close(FILE1);
open FILE2, "$f2" or die "Could not open file: $! \n";
while(my $line =<FILE2>) {
$results{$line}++;
}
close(FILE2);
open (OUTFILE, ">$outfile") or die "Cannot open $outfile for writing \
+n";
foreach my $line (keys %results) {
print OUTFILE "$line\n" if $results{$line} == 1;
}
close OUTFILE;
Please can someone help me? I really don't know how to fix this
Thank you
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|