ヘッダー行とデータの前にコメント テキストを含む CSV ファイルがあり、さらに操作するためにハッシュとして読み込みたいと考えています。主キーのハッシュは、2 つのデータ値の組み合わせになります。どうすればいいですか?
- パターン「index」を使用してヘッダー行を検索します
- キーにヘッダーを使用する
- ファイルの残りを読み込みます。
CSV の例
#
#
#
#
Description information of source of file.
index,label,bit,desc,mnemonic
6,370,11,three,THRE
9,240,23,four,FOR
11,120,n/a,five,FIV
望ましいハッシュの例
( '37011' => { 'index' => '6', 'label' => '370', 'bit' => '11', 'desc' => 'three', 'mnemonic' => 'THRE'}, '24023' => {'index' => '9', 'label' => '240', 'bit' => '23', 'desc' => 'four', 'mnemonic' => 'FOR'}, '120n/a' => {'index' => '11', 'label' => '120', 'bit' => 'n/a', 'desc' => 'five', 'mnemonic' => 'FIV'} )