02,29031990,feb,21,5
02,29031990,feb,18,5
02,29031990,feb,20,5
02,29031990,feb,21,5
####
Unit4872,29031990,01,0
Unit4873,29031990,03,0
Unit4874,29031990,02,4
Unit4875,29031990,02,3
Unit4876,29031990,02,2
Unit4877,29031990,02,1
Unit4878,29031990,02,0
####
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
####
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.
####
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper qw(Dumper);
my $filea = $ARGV[0];
my $fileb = $ARGV[1];
open ( FA, '<', $filea) || die ( "File $filea Not Found!" );
open ( FB, '<', $fileb) || die ( "File $fileb Not Found!" );
my %ts;
my @LAST_PLC;
while ( ) {
chomp;
my($Unit, $date, $mnt, $qtde) = split ",";
push @{ $ts{$date,$mnt} }, $Unit;
push @LAST_PLC, ($Unit);
}
my $last_one = pop @LAST_PLC;
#print $last_one."\n";
my $count=1;
my @FIRST_PRICE;
my $result;
my @FINAL;
my $price;
while ( ) {
chomp;
my($mnt,$date,$att,$idx,$max) = split ",";
push @FIRST_PRICE, ($idx);
$price = shift @FIRST_PRICE;
#if ( exists( $ts{$date,$mnt} ) ){
my $Unit = shift @{$ts{$date,$mnt}};
if ( ( $max - $count ) eq 1 ) {
#print join(",", $last_one, $date, $mnt, $att, $idx, $max, $count)."\n";
#} else {
print join(",", $Unit, $date, $mnt, $att, $idx, $max, $count)."\n";
}
#push @FINAL, (join(",", $Unit, $date, $mnt, $att, $idx, $max, $count, $last_one)."\n");
$count++;
#}
}
#print @FINAL;