PilotinControl has asked for the wisdom of the Perl Monks concerning the following question:
Good Afternoon Esteemed Monks!
My question is simple and the code is posted below for review. I have 2 data files and 2 columns and the data from one file needs to be output to one column and the data from file two needs to be output to the second column. Now my question is in order to accomplish this do I need to have a while loop instead of 2 foreach loops? Or can I have 1 for each loop and a two column formatted output? I'm a bit confused. Thanks in advance!
End Updateopen(MYINPUTFILEONE, "inbndtrk1.txt"); open(MYINPUTFILETWO, "inbndtrk2.txt"); $| = 1; my @linesone = <MYINPUTFILEONE>; my @linestwo = <MYINPUTFILETWO>; close (MYINPUTFILEONE); close (MYINPUTFILETWO);
printf ("%-15s %-15s\n", "================================="); printf ("%-15s %-15s\n", "| INBOUND TRACK 1 | INBOUND TRACK 2 |"); printf ("%-15s %-15s\n", "=====================================\n"); foreach (@linesone) { chomp; my @field = split(":"); my $format = "%-5s %-6s\n"; printf ($format, $field[1], $field[2]); } foreach (@linestwo) { chomp; my @field2 = split(":"); my $format2 = "%-5s %-6s\n"; printf ($format2, $field2[1], $field2[2]);
OR the foreach loops can be combined
UPDATEforeach (@linesone, @linestwo) { chomp; my @field2 = split(":"); my $format2 = "%-5s %-6s\n"; printf ($format2, $field2[1], $field2[2]);
__DATA__ 1:B&O:101 2:B&O:102 __DATA__ 1:CSXT:1001 2:CSXT:1002
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Two Column Data
by kcott (Archbishop) on May 11, 2015 at 23:33 UTC | |
by PilotinControl (Pilgrim) on May 12, 2015 at 00:14 UTC | |
|
Re: Two Column Data
by edimusrex (Monk) on May 11, 2015 at 19:09 UTC | |
by PilotinControl (Pilgrim) on May 11, 2015 at 19:31 UTC | |
by edimusrex (Monk) on May 11, 2015 at 20:04 UTC | |
by PilotinControl (Pilgrim) on May 11, 2015 at 22:11 UTC | |
by Laurent_R (Canon) on May 12, 2015 at 18:04 UTC | |
|
Re: Two Column Data
by Laurent_R (Canon) on May 11, 2015 at 18:53 UTC | |
by PilotinControl (Pilgrim) on May 11, 2015 at 19:01 UTC | |
by Laurent_R (Canon) on May 11, 2015 at 19:44 UTC | |
by PilotinControl (Pilgrim) on May 11, 2015 at 19:54 UTC | |
by Laurent_R (Canon) on May 11, 2015 at 20:12 UTC | |
| |
by Laurent_R (Canon) on May 11, 2015 at 19:36 UTC | |
|
Re: Two Column Data
by jeffa (Bishop) on May 12, 2015 at 17:06 UTC |