?

Log in

No account? Create an account

December 7th, 2006

first Ruby program

Here is my first Ruby program. Can anyone guess what it does? :)

totalWords = 0
Dir["/chuck/drupal-pot/*.pot"].each do |fileName|
  fileWords = 0
  contents = File.read("#{fileName}")
  contents.scan(/msgid "(.+)"/) do |x| 
    line = x.join.gsub(/<\/?[^>]*>/, "")
    line.gsub!(/[%&\\\/]\w+/, "")
    line.scan(/[\w-]+/) do |y| 
      fileWords += 1
    end 
  end
  print "#{fileWords}: #{fileName}\n"
  totalWords += fileWords
end
print "#{totalWords} words"

Latest Month

November 2016
S M T W T F S
  12345
6789101112
13141516171819
20212223242526
27282930   
Powered by LiveJournal.com
Designed by Tiffany Chow