If you just want to print the table you don't need to store anything. If you need to manipulate the data (including using string lengths of the data to format the table nicely) then use an array of hashes.

In any case, a neat way to manage the file is to use the first field name as the line end string so you can read an entire record at a hit:

#!/usr/bin/perl use warnings; use strict; use 5.010; my $startField = "Some Field :"; my $format = "%-15s %8s %8s %6s\n"; printf $format, 'something', 'number1', 'number2', 'word'; local $/ = $startField; while (defined (my $rec = <DATA>)) { next if $rec eq $startField; # Skip empty first record my @fields = split "\n", $rec; my @values; $fields[0] = $startField . $fields[0]; # Restore field label for my $field (@fields[0 .. 3]) { my (undef, $value) = split ': ', $field, 2; push @values, $value; } printf $format, @values; } __DATA__ Some Field : some value Another Field: 1234 Different One: 5678 Yet Another : foo line of uninteresting stuff Some Field : some else Another Field: 4321 Different One: 8765 Yet Another : bar more junk Some Field : another value Another Field: 1122 Different One: 5566 Yet Another : baz

Prints:

something number1 number2 word some value 1234 5678 foo some else 4321 8765 bar another value 1122 5566 baz

Note the local $/ = $startField; line.

True laziness is hard work

In reply to Re: Extracting and manipulating a range of lines by GrandFather
in thread Extracting and manipulating a range of lines by joeymac

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.