The similarity in the two programs should suggest 'subroutine' to you. Call it once for each file, have it pass back the array of unique lines you are already creating. Use a similar method to your %seen to populate your final hash with the values from the file2 array, removing entries that appear in the file1 array.
It would be nice to see an example of what the input file looks like.
UPDATE - suggested subroutine
my @array1 = unique($filename1); sub unique { my ($file) = shift; my (%seen); open my $fh, '<', $file or die "Could not open $file\n"; while(<$fh>) { chomp; $_ =~ m/(RC=\d{4})/; $seen{$_} = 1; } close $fh; return keys %seen; }
In reply to Re: Newbie, need help extracting strings from two files and comparing
by GotToBTru
in thread Newbie, need help extracting strings from two files and comparing
by soulbleach
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |