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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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, details, 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, summary, 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.