Your analysis of what the code is doing is mostly correct. In places, you indicate that operations are being performed on "files"; both solutions are reading the files line-by-line, and those operations are being performed on "records". Consider these corrections:

#remove spaces from both the beginning orand the end of the filerecord
# splits the filesrecords based on ...

You also appear to have misunderstood the LIMIT argument of split: you've used a value of 4 in two places, which doesn't make much sense as the maximum number of fields of any record is 3. Further reading of that documentation will explain why "@fields = split;" needs no arguments nor any preprocessing to trim whitespace.

The data structures produced by the two solutions are different: an HoA and an HoHoA. We both provided a link to perldsc: perhaps you need to read, reread or study in more detail.

The part that seems to elude you, in both cases, is how to translate the information in the data structures to whatever output format you need. You wrote (at the end of each of those analyses, respectively):

"My issue now comes when I need to print out the content in a structure way, ..."
"This is the part that gives me issues since I need to print the values in a specified format, ..."

Without any knowledge of the required output format, there's no way we can help. Again, the perldsc documentation has several sections on accessing the data in complex structures: the answer probably lies therein.

There are a few other areas where it looks like you really don't understand certain fundamentals. For instance, using the name $line for the variable that holds a key in:

foreach my $line(keys %hash) { print $line }

would seem to indicate that you don't know what keys does.

I would recommend that you bookmark perlintro and refer to it often. Make sure you understand the very basic information it presents, then follow links to related functions, in-depth documentation, tutorials, advanced topics, and so on, as necessary. For instance, the section on Hashes has links to keys and values (I half suspect that, in the code previously mentioned, "values %hash" was probably closer to what you wanted, instead of "keys %hash"); you'll also find many others such as perldata (fuller details), perlreftut (tutorial), and even perldsc (advanced topic already mentioned). Do note that's just some of the links in one of many sections: the entire document is like that and I think you'll find it a most useful resource.

— Ken


In reply to Re^3: perl parsing by kcott
in thread perl parsing by cbtshare

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.