Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
To start: I have a file that looks a bit like what's below, format-wise:
/* SOME COMMENT HERE */ /* MORE COMMENT */ /* Description - information */ options { option1 value; option2 value; option3 "value"; option4 { value1; value2; }; }; /* identifier1 ID 123456 */ object "identifier1" in { option1 value; option2 "value"; option3 { value1; value2; }; option4 { value; }; }; /* identifier2 ID 234561 */ object "identifier2" in { option1 value; option2 "value"; option3 { value1; value2; }; option4 { value; }; }; /* identifier3 ID 345612 */ object "identifier3" in { option1 value; option2 "value"; option3 { value1; value2; }; option4 { value; }; }; /* EOF */

I hope the anonymzing isn't too problematic.

At any rate, I need to pull data out of this file, and I can't guarantee the availability of any non-core modules on whatever system this ends up running on.

So, step 1 for me, is to get all the bits starting with object ... { and going until the next }; pulled out so I can deal with them from there. I'm thinking a regex that will grab each instance as a single multi-line string, and shoving them all into an array, but I'm open to suggestions. Each file may have rather a lot of these objects, but unfortunately I have no way of determining how many in advance.

What I've tried: I've been playing on Regex101 to test some various ideas and try to tweak a possible regex match. They don't have anything Perl-specific, but I've found it handy in the past for testing and tweaking. Alas, I keep ending up with everything or nothing. Getting the opening line or the closing line for each object is easy enough, but grabbing both and whever happens to be in between them is proving more problematic, and I end up with the everything-or-nothing problem.

Help, monks? Am I missing some blatently obvious solution?

What part of v_e = sqrt(2GM/r) don't you understand? It's only rocket science!

In reply to Regex Question by jedikaiti

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2022-08-10 17:47 GMT
Find Nodes?
    Voting Booth?

    No recent polls found