From: Randy Kramer Date: 2007-10-18T02:49:25+09:00 Subject: Re: Compound conditionals in case when statements? Syntax? --Boundary-00=_SqkFHVRI2sVWoto Content-Type: Multipart/Mixed; boundary="Boundary-00=_SqkFHVRI2sVWoto" --Boundary-00=_SqkFHVRI2sVWoto Content-Type: text/plain; charset="iso-8859-6" Content-Transfer-Encoding: 7bit Content-Disposition: inline Oops, I had a dumb mistake in one of those two commented out lines in askconvert. Fixing them doesn't solve the problem, but if you don't fix them you won't get the program to work. Attached is a revised copy of askconvert. Sorry about that! Randy Kramer On Wednesday 17 October 2007 01:25 pm, Randy Kramer wrote: > I've tried the suggested approaches and variations that I could think of, and > still no luck. --Boundary-00=_SqkFHVRI2sVWoto Content-Type: application/x-ruby; name="askconvert" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="askconvert" #! /usr/bin/env ruby # This is iter(ation)-4 (in progress) of ruby program askconvert to convert (initially) askRhk03 formatted files to askRhk04 format. (Later versions may perform additional conversions.) This version does work only for the hard coded conversion of file test.txt to test.aml. Iter-5 will presumably address getting the filenames from the command line. Iter-4 is sort of a break--code cleanup and maybe some comments--much as it is against my religion, I'm sort of trying to see to what extent this is (or can be made) "self-documenting"--I do have plenty of documentation (some pretty rough) in other files like askconvert.dev.aml. File.open("test.aml", "w") do |f| first_record = true new_record = false titles = Array.new File.open("test.txt").each do |line| case line when /^\x80\x81\x82\x83$/ new_record = true # when new_record && /^---\+\+ (.*)/ =~ line # titles.push $1.strip # the previous two lines could replace the next five lines if the previous two lines worked (or I could change the case statement to an if, elsif, elsif ... (or whatever)--case just seemed more "elegant" somehow--I'll wait and see if anybody can show me how to get those two lines to work. when /^---\+\+ (.*)/ if new_record titles.push $1.strip else f.puts line.rstrip + "\n" end else if new_record then # I could take the next 14 lines and "move" them to a module / method named something like "process_header"--I'd probably also learn something by doing so. I think I'm "learned out" for the moment. ;-) unless first_record then f.puts "morF\n\n" else first_record = false end if titles.length == 3 then title = titles.pop titles.reverse! else title = titles.shift end f.puts "From \"" + title + "\" " + %x{date -u +"%a %b %d %T %Z %Y"} + "Date: " + %x{date +"%D %H:%M %P %Z"} + "Subject: " + title + "\n" unless titles.empty? f.puts "\n" titles.each { |title| if title.strip.length > 0 then f.puts "T: " + title + "\n" end} f.puts "\n" end titles.clear new_record= false else f.puts line.rstrip + "\n" end end end f.puts "morF\n" end --Boundary-00=_SqkFHVRI2sVWoto-- --Boundary-00=_SqkFHVRI2sVWoto--