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
In reply to Two Column Data by PilotinControl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |