in reply to Re: Merge the difference between two files and save it on the first file. Also update the first file with info in second file.
in thread Merge the difference between two files and save it on the first file. Also update the first file with info in second file.

Hi! I cam across this example which is supposed to put the difference of the two files in b_array. Then i was thinking of merging it. But it still doesn't solve my problem of updating the file with latest values.
use strict; use warnings; use constant { FILE_A => './kma', FILE_B => './kma2', }; my %a_hash; my @a_array; my @b_array; open my $a_fh, "<", FILE_A; while ( my $line ~= <$a_fh> ) { chomp $line; $line = /^(.+?);/; # This strips the first field from the line $a_hash{$1} = 1; # Now, I'll use the first field as my index + to my hash push @a_array, $line; # This adds the line to the end of the arra +y } close $a_fh; open my $b_fh, "<", FILE_B; while ( my $line = <$b_fh> ) { $line ~= /^(.+?);/; if ( not exists $a_hash{$1} ) { push @b_array, $line; } } close $b_fh; my @combined_array = sort (@a_array, @b_array); print "content of my combined array = @combined_array";
  • Comment on Re^2: Merge the difference between two files and save it on the first file. Also update the first file with info in second file.
  • Download Code