Hi EBK,
I am not 100% sure I understood your requirements, but try this out:
#! /usr/bin/env perl use strict; use warnings; use autodie; use 5.10.0; open my $fa, '<', 'file-a'; open my $fb, '<', 'file-b'; my %fa; my %fb; while (<$fb>) { chomp; my @F = split ','; push @{ $fb{"$F[2]:$F[1]"} }, $_; } while (<$fa>) { chomp; my @F = split ','; push @{ $fa{"$F[0]:$F[1]"} }, $_; } foreach my $key (keys %fa) { for my $i ( 0 .. $#{ $fa{$key} } ) { my @A = split ',', $fa{$key}[$i]; my @B = split ',', $fb{$key}[$i]; say join ',', $B[0], $B[1], $B[2], $A[2], $A[3], $A[4], $i + 1; } if ( @{ $fa{$key} } + 1 == @{ $fb{$key} } ) { my @A = split ',', $fa{$key}[-1]; my @B = split ',', $fb{$key}[-1]; say join ',', $B[0], $B[1], $B[2], $A[2], $A[3], $A[4], scalar @{ $fb{$key} }; } }
Output:
Unit4874,29031990,02,feb,21,5,1 Unit4875,29031990,02,feb,18,5,2 Unit4876,29031990,02,feb,20,5,3 Unit4877,29031990,02,feb,21,5,4 Unit4878,29031990,02,feb,21,5,5
Hope this helps,
Jim
Edit: As another monk pointed out in another of your questions, it seems like you could really benefit from some kind of SQL database. Seems like you want to do a join on two tables.
πάντων χρημάτων μέτρον έστιν άνθρωπος.
In reply to Re: Controlling the count in array
by jimpudar
in thread Controlling the count in array
by EBK
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |