ミームの死骸を待ちながら

We are built as gene machines and cultured as meme machines, but we have the power to turn against our creators. We, alone on earth, can rebel against the tyranny of the selfish replicators. - Richard Dawkins "Selfish Gene"

We are built as gene machines and cultured as meme machines, but we have the power to turn against our creators.
We, alone on earth, can rebel against the tyranny of the selfish replicators.
- Richard Dawkins "Selfish Gene"

"Ruby Recipe 061"「,」で区切られたデータ(CSV)を処理する


CSVを読む方法、書く方法。このレシピはよく使いそうなので覚えておこう。

RubyCSVを読み込む

require 'csv'
CSV.parse("data.csv"){|row|
     p row
     }

RubyCSVを出力

下記参照。writterを呼ぶのは一度だけっぽい。


以上

Rubyレシピブック 第2版 268の技

Rubyレシピブック 第2版 268の技

より


まぁ書いたのはこんなちょっとしたスクリプト


今日「必要に応じて」Rubyレシピブック 第2版 268の技を調べながら書いたわけだが、書いたのはコレ↓
大したことやってないが、僕にとっては達成感を得るのに十分だ。1分でこれだけ書けるスーパーハカーになりたいなぁ

#! /usr/bin/env ruby

require 'csv'

deltaGary = []
File.readlines("NN_gb_com.all.out").each{|line|
  egbmatch = /EGB/.match(line)
  if line =~ /EGB/
    deltaG = egbmatch.post_match.strip.sub!("=", "").strip
    deltaGary << deltaG.to_i
  end
}

  picosecond = 0
CSV.generate("output.csv", ?, ){|writer|
  deltaGary.each{|value|
  writer << [picosecond, value]
  picosecond = picosecond + 10
  }
}