Unique Properties – Revisited

Back in August, I posted a simple Java utility for sorting out the definitive property value when a property is defined multiple times in a properties file. Here’s a simple Ruby script that does the same thing, but with far fewer bytes:

#Get filename
puts "Enter Properties File Name:"
fname = gets.strip

# Create a unique collection of keys,
# skipping comments
File.readlines(fname).each do |line|
  if line =~ /^([^#.]+)[=,:](.+)/
    propHash[$1.rstrip] = $2.lstrip

#output the results
propHash.keys.each do |k|
  puts "#{k}=" + propHash[k]

2 thoughts on “Unique Properties – Revisited”

  1. Your Java code is checking for the length of the command-line arguments whereas your Ruby script doesn’t.

    Besides that, you could have used LineNumberReader to make your Java code more concise and readable.

    Having said that my preference is to use a scripting language for developing such handy scripts (just like you) cause it takes less time to DO THE THING, especially in Linux (and OSX and Solaris and BSD and whatever but Windoze :-)

    AnonymousJoward ;-)

  2. AJ:
    Sure, the Java code could have been written to be more concise, readable. and efficient. LineNumberReader or something fancy with RandomAccessFile.

    You’re right: a scripting language is definitely the way to go for these quick and dirty utilities. I’m just digging into Ruby, so I thought I’d try a rewrite of this util.

    Thanks for the comment!

Comments are closed.