Perl Monk, Perl Meditation | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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 # splits the 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:
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
|
|