G'day perlynewby,
"... I do not know how to add multiple values to key in a hash."
See "perldsc - Perl Data Structures Cookbook". There are links at the end to more detailed information.
"Clearly, I do not understand how to manipulate the array of elements to create a table equally align."
There are a variety of options. In the example code below, I've used formats — see sprintf for a full description of formatting options.
Update (disambiguation): "formats" (used in the previous paragraph) does not refer to "perlform - Perl formats".
"open (DATA,'<',$infile) ..."
Use lexical filehandles instead of package variables — see open. In this case, DATA is a poor choice; not only because it is a package variable but also because it's special — see "perldata: Special Literals".
"... or die "could not open the $infile: $!";"
Consider using the autodie pragma. It saves you having to type the "or die ..." code and is far less error-prone.
Here's an example showing the use of formatting:
#!/usr/bin/env perl use strict; use warnings; my $fmt = "%-11s % 12.6f % 12.6f %s\n% 24.6f % 12.6f %s\n"; while (<DATA>) { my @cols = split; $_ = <DATA>; push @cols, split; printf $fmt, @cols; } __DATA__ MM_STD_gate -61.771653 -45.472441 mils -1569.000000 -1155.000000 microns RFN_a -91.102362 68.307087 mils -2314.000000 1735.000000 microns RFN_b -62.165354 68.307087 mils -1579.000000 1735.000000 microns RFN_c -51.417322 68.307087 mils -1306.000000 1735.000000 + microns
Here's the output:
MM_STD_gate -61.771653 -45.472441 mils -1569.000000 -1155.000000 microns RFN_a -91.102362 68.307087 mils -2314.000000 1735.000000 microns RFN_b -62.165354 68.307087 mils -1579.000000 1735.000000 microns RFN_c -51.417322 68.307087 mils -1306.000000 1735.000000 microns
— Ken
In reply to Re: Help with Creating a Table from array ref I parsed in
by kcott
in thread Help with Creating a Table from array ref I parsed in
by perlynewby
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |