perlquestion
jedikaiti
To start: I have a file that looks a bit like what's below, format-wise:<br />
<readmore>
<code>
/* 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 */
</code>
<p>I hope the anonymzing isn't too problematic.</p>
</readmore>
<p>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.</p>
<p>So, step 1 for me, is to get all the bits starting with <code>object ... {</code> and going until the next <code>};</code> 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.</p>
<p>What I've tried: I've been playing on [https://regex101.com/|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.</p>
<p>Help, monks? Am I missing some blatently obvious solution?</p>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-826783">
<br/>What part of v_e = sqrt(2GM/r) don't you understand? It's only rocket science!
</div></div>