Let me explain more clearly now. I ask some days ago about to join two files with conditional and loop. I got to solve partially the problem but I need to change these demand to the following situation.

File A with 9 or more lines and the second column is the key.
life_1,23032018,a_0300,true,3 life_1,23032018,a_0200,true,4 life_1,23032018,a_0100,true,3 life_1,23032018,c_0300,true,21 life_1,23032018,c_0200,true,21 life_1,23032018,c_0100,true,25 life_1,23032018,d_0300,true,23 life_1,23032018,d_0200,true,21 life_1,23032018,d_0100,true,24
File B with 800 or more lines and the second column is the key.
201810021569661,23032018 201810021569678,23032018 201810021569685,23032018 201810021569708,23032018 201810021569715,23032018 201810021569722,23032018 201810021569739,23032018 201810021569746,23032018 201810021569753,23032018 201810021569760,23032018
I am using Perl in the File A and using the 5th column to run through the number of lines of the File B and creating a third file. But when the for loop of the 5th column from File A finish I have to stop in the line in the File B and continue the next loop in the same line and not to restart from the First line in File B. The result I got with my script is. The second column values are repeated on each loop. For example, the value 201810021569661 is showing 3 times in my result.
Loop tot->3 life_1,201810021569661,a_0300 life_1,201810021569678,a_0300 life_1,201810021569685,a_0300 Loop tot->4 life_1,201810021569661,a_0200 life_1,201810021569678,a_0200 life_1,201810021569685,a_0200 life_1,201810021569739,a_0200 Loop tot->3 life_1,201810021569661,a_0100 life_1,201810021569678,a_0100 life_1,201810021569685,a_0100
The result I want is this. Look the result is the second column does not repeat. Now the value 201810021569661 is showing only one time.
Loop tot->3 life_1,201810021569661,a_0300 life_1,201810021569678,a_0300 life_1,201810021569685,a_0300 Loop tot->4 life_1,201810021569708,a_0200 life_1,201810021569715,a_0200 life_1,201810021569722,a_0200 life_1,201810021569739,a_0200 Loop tot->3 life_1,201810021569746,a_0100 life_1,201810021569753,a_0100 life_1,201810021569760,a_0100
With the help of all of you, I did something but it is restarting the File B on each loop.
use strict; use warnings; use Data::Dumper qw(Dumper); my $filea = FileA; my $fileb = FileB; open ( FA, '<', $filea) || die ( "File $filea Not Found!" ); open ( FB, '<', $fileb) || die ( "File $fileb Not Found!" ); my %ts; while ( <FB> ) { chomp; my($ids, $timestamp) = split ","; push @{ $ts{$timestamp} }, $ids; } while ( <FA> ) { chomp; my($life,$timestamp,$cls,$bool,$tot) = split ","; print STDERR "Loop tot-> $tot"; scalar <STDIN>; for my $ids ( @{ $ts{$timestamp} } ) { last if $tot-- < 1; print join(",",$life, $ids, $cls )."\n"; } }

In reply to Perl to run 2 files and print the third with loop 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.