Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi, All!

It's been a while. Ellated to be back!

I have files (Juniper/NetScreen's NSM *.nml files, similar to CheckPoint management station *.W or object*.C files) I need parsed to retrieve specific information.

I'm looking to create hashes of hashes, or at least I think that is the way to go. I need a nudge (and please just a nudge as I'm trying to get my perl legs under me again) toward how to slurp such a file into something useful.

The tabs/parentheses are messing me up big time. Anther hurdle is creating arbitrary hashes (of hashes etc.) by a variable and properly handling relative depth. Lastly, this has to be maintainable (by someone with equal or lesser perl skills to my atrophied ones).

Basically, I don't think I'm approaching my source data properly.

I'd post what I have now (reading the whole file into one big ordered hash and positional searching a la Recipe 6.14) but its broken beyond repair, at best failed to execute with taint checking and -w and 'use strict;' enabled, and exhibits shamefull coding practices beyond that.

UPDATE 3: Reordered and added a timely readmore tag as I'm on the Gates now.

Here is a small piece of the data (with leading 8 character tabs, as indentation is perhaps crutial):

				:rip (
					:bind_interface (false)
					:enable (false)
					:poison_split_horizon (enable
						:enable (
							:poison (false)
						:disable (null)
					:metric (1)
					:passive_mode (false)
					:authentication (no-authentication
						:multiple-md5 (
							:md5-key-values ()


Here is another snipit of the source file, by request. Please see idnopheq's scratchpad for a full source file.

        :members ()
        :global-pro (
                :report-manager (
                        :primary ("&0.server.1")
                        :alarm-attack (true)
                        :alarm-other (true)
                        :alarm-traffic (true)
                        :alarm-di (true)
                        :attack-stat (true)
                        :ethernet-stat (true)
                        :flow-stat (true)
                        :log-config (true)
                        :log-info (true)
                        :log-self (true)
                        :log-traffic (true)
                        :policy-stat (true)
                        :proto-dist (true)
                        :server-port (7800)
                        :user-service ()
For those who might wish to bring up the fw1rules tool, I've tried "liberating" portions thereof to achieve this end. However, it seems these types of files scream out for hashes of hashes (of hashes, etc.). Traversing every line and manually keeping track of tab depth seems a waste of resources (although I'm getting desperate enough to consider it again).

For those REALLY interested in the beast I need to tame, PM me and I will send you the full source data file.

UPDATE 0: a source data file is in idnopheq's scratchpad.

UPDATE 1: I will turn the solution into a module for general consumption once I'm able to get my mind around this. Maybe it'll even be flexible enough for CheckPoint and Juniper/NetScreen files!

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

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

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (7)
    As of 2018-06-25 10:35 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (126 votes). Check out past polls.