in reply to how to merge similar data

Here we go: (you may find a better way later)
#!/usr/bin/perl ### do original data open(COMPANIES, "+< ./data1") or die "can't open file: $!"; @contents = <COMPANIES>; close(COMPANIES); chomp(@contents); open(INFO, "+< ./info.csv") or die "can't open file: $!"; @contents2 = <INFO>; close(INFO); chomp(@contents2); ### do data to be merged $merges = 0; foreach $record (@contents) { @fields = split(/\|/,$record); $tidm=$fields[0]; foreach $record2 (@contents2) { @fields2 = split(/\|/,$record2); $tidm_inf=$fields2[0]; if ($tidm eq $tidm_inf){ $merged[$merges] = join("|",(@fields, @fields2[2..8])); $merges++; } } } ### print merged open(FILE,">outfile.dat"); foreach $merge(@merged){ print "$merge\n"; } close(FILE);

Replies are listed 'Best First'.
Re: Re: how to merge similar data
by alexiskb (Acolyte) on Sep 19, 2002 at 10:38 UTC
    Perfect, thanks katgirl, that works perfectly!
    i shall study your code well. thanks very much indeed.