Parse file to hash in Ruby

Posted by Taschetto on Stack Overflow See other posts from Stack Overflow or by Taschetto
Published on 2013-10-17T15:51:53Z Indexed on 2013/10/17 15:54 UTC
Read the original article Hit count: 189

Filed under:
|

I'm a ruby newcomer who's trying to read a text file (a Valgrind simulation output) like this:

--------------------------------------------------------------------------------
Profile data file 'temp/gt_1024_2_16.out'
--------------------------------------------------------------------------------
I1 cache:         1024 B, 16 B, 2-way associative
D1 cache:         32768 B, 64 B, 8-way associative
LL cache:         3145728 B, 64 B, 12-way associative
Profiled target:  bash run.sh
Events recorded:  Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
Events shown:     Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
Event sort order: Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
Thresholds:       99 0 0 0 0 0 0 0 0
Include dirs:     
User annotated:   
Auto-annotation:  off

--------------------------------------------------------------------------------
       Ir    I1mr  ILmr      Dr  D1mr  DLmr      Dw  D1mw  DLmw 
--------------------------------------------------------------------------------
1,894,017 246,981 2,448 519,124 4,691 2,792 337,817 1,846 1,672  PROGRAM TOTALS

// other data

I want to extract the PROGRAM TOTALS table and put it into a hash. Something like...

myHash = { :Ir => 1894017, :I1mr => 246981, ILmr => 2448, ..., DLmw => 1672 }

What are the best options for doing this? Could the CSV classes help me out? Thanks a bunch.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about valgrind