[Cialug] Algorithm; Cutting Up A File

Todd Walton tdwalton at gmail.com
Wed Dec 13 06:52:32 CST 2006


On 12/12/06, David W. Body <davidbody at bigcreek.com> wrote:
> Ruby (in a Perlish style):
>
> #!/usr/bin/env ruby
> in_file = ARGV[0]
> File.read(in_file).scan(/<(.*)>(.*)<\/\1>/m).each do |match|
>     out_file = in_file.gsub(/\./, "-#{match[0]}.")
>    File.open(out_file, "w") {|f| f.print match[1].strip }
> end

How ironic that Tim's perl is clearer than this, given their
respective reputations!

-todd


More information about the Cialug mailing list