in reply to Perl to run 2 files and print the third with loop
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl to run 2 files and print the third with loop
by Borodin (Sexton) on Apr 01, 2018 at 16:43 UTC | |
by jimpudar (Pilgrim) on Apr 01, 2018 at 23:51 UTC | |
by jimpudar (Pilgrim) on Apr 02, 2018 at 06:35 UTC | |
by EBK (Sexton) on Apr 02, 2018 at 17:29 UTC | |
|
Re^2: Perl to run 2 files and print the third with loop
by EBK (Sexton) on Apr 01, 2018 at 21:45 UTC | |
by AnomalousMonk (Archbishop) on Apr 01, 2018 at 21:48 UTC | |
by kcott (Archbishop) on Apr 02, 2018 at 04:52 UTC |