It's hard to see the need for a module to do that. Especially as the '----' line is very specific to your data format; thus would need a special case or option.

And because it is very simple to do:

#! perl -slw use strict; use Data::Dump qw[ pp ]; my @keys = split ' ', scalar <DATA>; <DATA>; ## discard ----- my @data = map{ my %hash; @hash{ @keys } = split ' '; \%hash; } <DATA>; pp \@data; __END__ Name UPP Age Career Terms -------- ------ --- ---------- ----- Rejnaldi 765987 38 Citizen 6 Lisandra 6779AA 34 Noble 4 Kuran 899786 42 Marine 8

Produces:

C:\test>junk [ { Age => 38, Career => "Citizen", Name => "Rejnaldi", Terms => 6, UP +P => 765987 }, { Age => 34, Career => "Noble", Name => "Lisandra", Terms => 4, UPP +=> "6779AA" }, { Age => 42, Career => "Marine", Name => "Kuran", Terms => 8, UPP => + 899786 }, ]

Of course, someone will complain that it doesn't handle names with spaces, and so you need to switch to fixed field record processing:

#! perl -slw use strict; use Data::Dump qw[ pp ]; my @keys = unpack 'A8xA6xA3xA10xA5', scalar <DATA>; <DATA>; ## discard my @data = map{ my %hash; @hash{ @keys } = unpack 'A8xA6xA3xA10xA5', $_; \%hash; } <DATA>; pp \@data; __END__ Name UPP Age Career Terms -------- ------ --- ---------- ----- Rejnaldi 765987 38 Citizen 6 Lisandra 6779AA 34 Noble 4 Kuran 899786 42 Marine 8

Which produces the same output. But ... they'll say: what if you want to read lots of different files in the same format?

Then you need to determine the fields sizes from the data:

#! perl -slw use strict; use Data::Dump qw[ pp ]; my @keys = scalar( <DATA> ) =~ m[(\S+\s*)\s]g; my $templ = join 'x', map{ 'A' . length() } @keys; @keys = map{ $_ =~ s[\s+$][]; $_ } @keys; <DATA>; ## discard my @data = map{ my %hash; @hash{ @keys } = unpack $templ, $_; \%hash; } <DATA>; pp \@data; __END__

Again, same output.

But what if the keys can contain spaces? In which case you'll need to use a heuristic approach to locating the field boundaries


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

In reply to Re: Is there a "Here Table"? by BrowserUk
in thread Is there a "Here Table"? by rje

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.