[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

parsing advice

Reid Oda

3/6/2008 12:36:00 AM

[Note: parts of this message were removed to make it a legal post.]

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

1 Answer

Michael Fellinger

3/6/2008 2:40:00 AM

0

On Thu, Mar 6, 2008 at 9:35 AM, Reid Oda <reid.oda@gmail.com> wrote:
> 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?

http://p.rama...
Though 'most elegant' is a wide term, especially in Ruby.
Have fun learning!

^ manveru