Hi EBK,
You are quite close to the solution. Instead of looping over the array, try looping over the range from 1 to $tot.
Code looks like this:
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>; foreach ( 1 .. $tot ) { my $id = shift @{ $ts{$timestamp} }; print join(",",$life, $id, $cls )."\n"; } }
Using the shift operator ensures that no id is repeated.
Hope this helps!
Jim
In reply to Re: Perl to run 2 files and print the third with loop
by jimpudar
in thread Perl to run 2 files and print the third with loop
by EBK
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |