Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: perl parsing

by kcott (Archbishop)
on Oct 05, 2017 at 22:32 UTC ( [id://1200780]=note: print w/replies, xml ) Need Help??


in reply to Re^2: perl parsing
in thread perl parsing

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

Replies are listed 'Best First'.
Re^4: perl parsing
by cbtshare (Monk) on Oct 06, 2017 at 01:57 UTC
    Thank you for your guidance, I will be sure to go through all the material provided.Sorry I didnt specify te format I want, I typed it in after the edit and hit submit, guess it didn't accept it.The format I want is below and to place that format in multiple files :
    Brian Ipad Ipad other file Andrew iphone ipad
      "Thank you for your guidance, I will be sure to go through all the material provided."

      You're most welcome.

      "Sorry I didnt specify te format I want, I typed it in after the edit and hit submit, guess it didn't accept it."

      You can use the "preview" button as many times as you want prior to actually clicking the "create" button. I typically "preview" multiple times as I check links, fix typos, add clarifications, and so on.

      After hitting "create" you can still make modifications (you'll find an "edit" link with your post); however, please read "How do I change/delete my post?" before doing so.

      "The format I want is below and to place that format in multiple files : ..."

      Unfortunately, that's rather vague and leaves us guessing what you really want. Brian started with three ipads (lowercase); now he has two (capitalised). Andrew had an ipad; now he also has an iphone. The year information is not shown. And ryan (originally lowercase, but perhaps that needs capitalisation) has disappeared entirely.

      I suggest you attempt this yourself and, if you run into difficulties, bear those points in mind when posting a follow-up question. It would be useful to reference this thread in such a post (see "What shortcuts can I use for linking to other information?" if you're unsure how to do that). And, if you didn't already know, following the guidelines in "How do I post a question effectively?" and "Short, Self-Contained, Correct Example" will get you better and faster answers (i.e. rather than responses which are requests seeking missing information or clarification of what was posted).

      — Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1200780]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-03-29 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found