File B02,29031990,feb,21,5 02,29031990,feb,18,5 02,29031990,feb,20,5 02,29031990,feb,21,5
My keys I have matched are 1st with 2nd column from File A and 2nd with 3rd from file B. My rule is when both keys matched I will print 1st column from File B with 2nd, 1st, 3rd, 4th and 5th from File A and one counter of all rows of the File A. So, with combined these two files I have created this file: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
Now my situation is this. If my last number of my counter(in this case is 4) minus the 5th column from File A is 1, I have to get next line from File B adding add 1 more to counter and getting the last result of 4th column from File B. My result would be like that.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
This is my code so far. I was testing but I am caught in this code.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 ( <FB> ) { 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 ( <FA> ) { 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, $id +x, $max, $count, $last_one)."\n"); $count++; #} } #print @FINAL;
In reply to Controlling the count in array by EBK
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |