Re: [Wtr-general] [OT] - array nightmare
> I'm not comfortable with truncating the original file either. What I > would like to do is get the latest data, see what's not in the main > file, and append it. I'm reading this sentence as a set of requirements. Assuming that the arrays are small enough to not blow out the RAM on the machine, I'd do it like this: ## main_file = ['a','b','c',' '] latest_data = ['c','x'] not_in_main_file = latest_data - main_file puts "not in main file: " puts not_in_main_file puts "" new_log = main_file + not_in_main_file puts "new log contents after addition: " puts new_log ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] [OT] - array nightmare
Walter Kruse wrote: > Anyway, as I said, off topic so don't worry too much - this solves a > sort-term problem. > Just to be clear. I don't consider this line of questions to be off topic. Yes technically they are Ruby questions rather than Watir questions, but the are welcome on this forum. Bret ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] [OT] - array nightmare
Hi Chris I think the biggest issue is the difference between File.read and IO.readlines, and understanding when an array or a string is returned. I'm not comfortable with truncating the original file either. What I would like to do is get the latest data, see what's not in the main file, and append it. What I do now, is get the latest data, put the existing file into an array, merge the two and hack it with Array.sort.uniq, truncate the file and insert the new data. Anyway, as I said, off topic so don't worry too much - this solves a sort-term problem. Kind regards Walter -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris McMahon Sent: 16 April 2007 06:11 PM To: wtr-general@rubyforge.org Subject: Re: [Wtr-general] [OT] - array nightmare > The new array replaces all the data previously in the master log file. I get > a lot of redundant whitespace for some reason. It really is a hack - there > must be a better way to do it... > I'm not sure what the expected result here should be. Seems like a reasonable approach. What part is the hackiest? ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general ** Everything in this e-mail and attachments relating to the official business of MultiChoice Africa is proprietary to the company. Any view or opinion expressed in this message may be the view of the individual and should not automatically be ascribed to the company. If you are not the intended recipient, you may not peruse, use, disseminate, distribute or copy this message. If you have received this message in error, please notify the sender immediately by email, facsimile or telephone and destroy the original message. ** ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
Re: [Wtr-general] [OT] - array nightmare
> The new array replaces all the data previously in the master log file. I get > a lot of redundant whitespace for some reason. It really is a hack – there > must be a better way to do it… > I'm not sure what the expected result here should be. Seems like a reasonable approach. What part is the hackiest? ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general
[Wtr-general] [OT] - array nightmare
Hi list Off topic, but I am sure there is a better way to do what I'm doing. As my test script runs, I have a script which reads the windows event log every 5 minutes and produces three flat files with the output according to different criteria. The way I read the logs is with Microsoft's dumpel.exe utility which is called with system() and parameters from ruby. But, I need a continuous log file, so at the beginning of the script I create a master log file. Everytime the three new temp log files are written, I read the data into an array. I also read the master log file into an array. Then I have a simple if: oldbuffer = logfile.to_a newbuffer = nil newbuffer = rebootedarray.to_a | clearedarray.to_a | temparray.to_a newbuffer.each {|item| if not oldbuffer.include?(item) oldbuffer.push(item) if item > '' end } logfile.truncate 0 oldbuffer = oldbuffer.sort.uniq logfile.puts(oldbuffer) The new array replaces all the data previously in the master log file. I get a lot of redundant whitespace for some reason. It really is a hack - there must be a better way to do it... Walter Kruse Senior Test Analyst www.OBS-Consulting.com 082 660 7288 http://www.ou-ryperd.net ** Everything in this e-mail and attachments relating to the official business of MultiChoice Africa is proprietary to the company. Any view or opinion expressed in this message may be the view of the individual and should not automatically be ascribed to the company. If you are not the intended recipient, you may not peruse, use, disseminate, distribute or copy this message. If you have received this message in error, please notify the sender immediately by email, facsimile or telephone and destroy the original message. ** ___ Wtr-general mailing list Wtr-general@rubyforge.org http://rubyforge.org/mailman/listinfo/wtr-general