continue

Case Study 3: Simple Shell Scripting
pattern matching, file handling, system calls

Recompile all C files below "." which have been modified after their corresponding ".o" file.
....Ruby example, from pixel@mandrakesoft.com
Dir['**/*.c'].each{|c|
  o = c.sub('\.c$', '.o')
  if !FileTest.exist?(o) || File.stat(o) <= File.stat(c) then
    puts "compiling #{c} to #{o}"
    system("gcc", "-c", "-o", o, c)
  end
}
Ruby provides support for iteration (.each{|c|...}), pattern matching/replacement (c.sub(P1,P2)), system calls (system(Command,A1,A2,...)), recursive file filtering (Dir['**/*.c']), file property access (File.stat, FileTest).
continue


back to top


set preferences

LL2, Saturday 9 November 2002, Tim Hickey/Ken Anderson