Kiss your tedious tasks goodbye: 'Everyday Scripting With Ruby'

Chances are, you do some boring, repetitive data-related tasks at work -- ones a computer could easily do, if only it was told how.

"At one desk, a tester is entering test data into a database by hand. At another, a programmer is sifting through the output from a version-control system, trying to find the file she wants. At a third, a business analyst is copying data from a report into a spreadsheet. Why are these people doing work that computers could do perfectly well?" asks Brian Marick, author of Everyday Scripting With Ruby.

Well, this happens because they do one of the following:

  • Don't know how to automate their drudgery.
  • Believe that trying to automate the task would take even longer than just doing it by hand.
  • Automated a task once, but then the task changed, and updating the code is too much work.

These are all things Marick addresses in his book. While most people probably associate Ruby with the (relatively) hot new Rails Web development framework (see "The Top Five Technologies You Need to Know About in '07"), Marick pitches Ruby as a stand-alone scripting language. He says it's "quick to learn and easy to write."

Honestly, the main reason I'm interested in Ruby is because I want to learn Rails, not to write stand-alone scripts. However, after going through several of the book's examples, I agree that Ruby has some advantages in its own right.

My Ruby code seems easier to read days or weeks later than, say, scripts written in Perl. Perl is a powerful, flexible, robust language that could easily handle all the problems Marick presents, but I find it difficult to read my own Perl code a few months later, let alone anyone else's ever. On the other hand, Ruby snippets such as

@array = [1,2,3,4]
$n = @array.length


or

$date = Time.now

seem reasonably intuitive.

But for me right now, a key drawback to Perl is that I don't have to write object-oriented code, because there's both object-oriented programming and non-OOP Perl syntax. This is great for a lazy editor who doesn't want to hassle with OOP, but not so great if he needs to learn it. Ruby, on the other hand, is OOP only, forcing me to start coding (and thinking) in objects.

In Everyday Scripting With Ruby, Marick presents four problems and then walks readers through the code needed to solve them. He starts with code to compare file inventories, followed by scripts to get information from a version-control system, "scrape" data from a Web site (and massage it into a spreadsheet-readable comma-delimited file) and monitor long-running programs.

Be advised that this is not a comprehensive book for learning the Ruby programming language.

1 2 Page 1
Page 1 of 2
  
Shop Tech Products at Amazon