Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Logic trouble parsing a formatted text file into hashes of hashes (of hashes, etc.)

by chromatic (Archbishop)
on Oct 16, 2004 at 19:31 UTC ( #399799=note: print w/ replies, xml ) Need Help??


in reply to Logic trouble parsing a formatted text file into hashes of hashes (of hashes, etc.)

Unless there's a CPAN module to handle this type of file, I'd consider building a finite state machine in Perl to handle the parsing. That way, you can read in a line, handle it -- starting or ending a state as necessary -- and move on.

One trick that might help is to keep a global or semi-global stack of the current position. If you're familiar with references, this would be a reference to the current position in the master hash. When you enter a new state, push a new hash reference on the stack. When you leave a state, pop the hash reference off. (Don't forget to store it in the master structure though.)

Does that make sense?


Comment on Re: Logic trouble parsing a formatted text file into hashes of hashes (of hashes, etc.)
Re^2: Logic trouble parsing a formatted text file into hashes of hashes (of hashes, etc.)
by idnopheq (Chaplain) on Oct 16, 2004 at 19:44 UTC
    No. I am totally baffled by your answer. But perhaps its the "nudge" I need, and I'll read the link you provided and knock some more dust off.

    I cannot thus far find a CPAN module to help me (beyond using Net::Telnet::Netscreen; visiting each box insecurely is no fun what so ever).

    THX!!!
    --
    idnopheq
    Apply yourself to new problems without preparation, develop confidence in your ability to to meet situations as they arrise.

      He's speaking of building a SAX-style parser for your file format. Recognize tokens, call functions when you find them, and keep track of context with package variables...

      Another alternative might be Parse::RecDescent or the YAPP module...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2015-07-07 10:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls