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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.