#!/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;