http://qs1969.pair.com?node_id=1175466

jedikaiti has asked for the wisdom of the Perl Monks concerning the following question:

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!