# Parsing advice

**URL:** <https://www.ruby-forum.com/t/parsing-advice/131102>\
**Category:** Ruby\
**Created:** [March 6, 2008, 1:36am UTC](https://www.ruby-forum.com/t/parsing-advice/131102 "2008-03-06T01:36:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brownerthanu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@brownerthanu](https://www.ruby-forum.com/u/brownerthanu)\
**Post date:** [March 6, 2008, 1:36am UTC](https://www.ruby-forum.com/t/parsing-advice/131102/1 "2008-03-06T01:36:33Z")

</div>

hi everyone,

i have a file that i want to parse. i’m used to doing this stuff  
recursively, and would like to know what the “ruby” style would be. the  
file is a series of tests, with the test name at the :start and the test  
parameters listed afterwards. here’s an example, though the complete  
file  
is much longer:

:start Perf\_Video\_Integrity  
Sample\_Rate 44100 :default 48000 88200 96000 176400  
192000  
:end

:start Perf\_Video\_Integ\_Play  
Session\_Name :default SessionName  
HW\_Buffer\_Size :default All 64 128 256 512 1024 2048 4096  
8192  
Play\_Time\_Minutes :default 20  
testType :default SPDIF ADAT  
:end

:start Perf\_Video\_Integ\_Rec  
Session\_Name :default SessionName  
HW\_Buffer\_Size :default All 64 128 256 512 1024 2048 4096  
8192  
Rec\_Time\_Minutes :default 20  
:end

currently, i have the file in an array of lines. i’d like a function to  
find the specified test (i.e. Perf\_Video\_Integrity), and return an array  
of  
the parameter lines. my specific question is, what is the most elegent  
way  
to build the control structure that extracts the relevant lines?

any advice is appreciated.

-reid

---

<div class="post-metadata">

**Author:** ![brownerthanu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e5b9ba/32.png) [@brownerthanu](https://www.ruby-forum.com/u/brownerthanu)\
**Post date:** [March 6, 2008, 3:41am UTC](https://www.ruby-forum.com/t/parsing-advice/131102/2 "2008-03-06T03:41:27Z")

</div>

On Thu, Mar 6, 2008 at 9:35 AM, Reid O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> :end  
> HW\_Buffer\_Size :default All 64 128 256 512 1024 2048 4096 8192  
> Rec\_Time\_Minutes :default 20  
> :end
> 
> currently, i have the file in an array of lines. i’d like a function to  
> find the specified test (i.e. Perf\_Video\_Integrity), and return an array of  
> the parameter lines. my specific question is, what is the most elegent way  
> to build the control structure that extracts the relevant lines?

[http://p.ramaze.net/741](http://p.ramaze.net/741)  
Though ‘most elegant’ is a wide term, especially in Ruby.  
Have fun learning!

^ manveru
