Getting user input from the command line in Groovy

I was going through Chris Pine’s excellent “Learn to Program“, re-doing all of the exercises in Groovy (since it’s Ruby-centric). I ran across one where I need to get user input. Ruby’s got its easy “gets” method; what about Groovy? Weeelllll, here’s the idiomatic Groovy way to do such a thing:

System.in.withReader {
print "Enter your input: "
def input = it.readLine()
}

Ouch! Easier than Java, but still orders of magnitude more complicated than Ruby. Still not a deal-breaker for me, though, since how many times in the real world do you get user input from the command line?

Advertisements

About buffalobillion

Web Developer, JavaScript Balrog, Java dude, Ruby/Rails enthusiast. Guitar Playa.
This entry was posted in Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s