From: Peter Bailey Date: 2006-05-20T05:24:17+09:00 Subject: Why won't this "if" clause work properly? Hi, I'm going nuts with this tiny script. I'm basically just doing a page count in a postscript print file. Even though I feed it jobs with an even number of pages, it still carries through with line 15, which should ONLY be run if it's an odd page count. When I do this in IRB, it works fine. In other words, if its' an even page count, it exits, like it should. Thanks. 1 Dir.chdir("c:/scripts/ruby/temp/test") 2 fedpsfiles = Dir.glob('fed*.ps') 3 #an array for the page count 4 fedpsfiles.each do |fedpsfile| 5 #totalpages = [] 6 #Read the whole file into memory. 7 contents = File.read(fedpsfile) 8 #Look for page entries and put them into an array. 9 totalpages = contents.scan(/^%%Page:.*[0-9]{1,5}$/) do 10 end 11 #If the totalpages.length, meaning the array count, is odd, then add a blank 12 # at the end of the file. 13 remainder = totalpages.length.to_i % 2 14 if remainder == 1 then 15 contents << "%%Blank page for Asura.\nshowpage\n" 16 #Write the whole file now back to the original file. 17 File.open(fedpsfile, "w") { |f| f.print contents } 18 else exit 19 end 20 end -- Posted via http://www.ruby-forum.com/.