Ruby for command line applications

Hi,

I am a Linux administrator and I use Perl for scripting.
I do not develop any web applications. My programs are command line
tools.

At this phase I am thinking to upgrade my programming language to either
Python or Ruby.

Considering the fact that I wonâ??t develop any web application, Which one
would be a better choice for me Perl or Ruby?

Thank you,
Alan

Of course, you can expect a bias on this mailing list, but I will
give my two cents.

Perl: Great for quick, concise scripts you may need to hack together.
Ugly syntax, but beautiful functionality.

Python: Not much experience here, so I can only say that I hear it is
pretty powerful, but a bit annoying to use, according to some.

Ruby: Good for those who like to make elegant solutions to their
problems. Tends to make readable programs that can be easily modified
later. More powerful than Perl (IMHO), but not as concise. Definitely
is the most enjoyable language to work with on a regular basis as it
does not hinder you with weird syntax or restrictions, for the most
part.

  • Jake McArthur

On 4/26/06, Alan M [email protected] wrote:

would be a better choice for me Perl or Ruby?

Thank you,
Alan

Ruby is incredibly well-suited to this.
As an example, many standard methods are either named (or aliased)
after standard shell commands.
FileUtils.cp, mv, ln
String#grep
etc, etc.

I recently introduced a sysadmin friend of mine to Ruby, and he raves
about how he can write something, come back to it later, and actually
tell what it does.
Apparently this is something Perl isn’t good at? Heh.

–Wilson.

On Wednesday 26 April 2006 3:31 pm, Jake McArthur wrote:

Ruby: Good for those who like to make elegant solutions to their
problems. Tends to make readable programs that can be easily modified
later. More powerful than Perl (IMHO), but not as concise. Definitely
is the most enjoyable language to work with on a regular basis as it
does not hinder you with weird syntax or restrictions, for the most
part.

I would argue that point. Back in 2002, when I was first learning Ruby,
I was
coming to it from many years of using Perl for everything. To my joy I
found
that, in general, my newbie-Ruby code was shorter and more readable than
equivalent Perl of a type that I would actually use in production.

I’m not talking the ultra-compressed, obfusicated, line-noise Perl, but
the
kind of thing one writes when one wants to have a chance of easily
understanding it again 6 months later.

For a while I delighted in taking my Perl production code and rewriting
parts
of it in Ruby, just to bask in it’s readability and it’s terseness. It
was a
joy.

So, speaking as someone who uses Ruby for command line tools and system
automation scripts, I strongly support the use of Ruby for those sorts
of
things, in lieu of Perl.

Kirk H.

On 4/26/06, Alan M [email protected] wrote:

would be a better choice for me Perl or Ruby?
This is exactly the space I came to Ruby from (and still spend most of
my time
in). I think Ruby is an excellent fit. It’s clean, powerful, and
concise. It let’s
you build the tools you want to, and be able to come back to in six
months and
still understand them.

Thank you,
Alan


Posted via http://www.ruby-forum.com/.


thanks,
-pate

On Apr 26, 2006, at 4:31 PM, Jake McArthur wrote:

More powerful than Perl (IMHO), but not as concise.

Could you given a small example program in Perl that is lengthier in
Ruby? (Just curious.)

James Edward G. II

On Apr 26, 2006, at 4:41 PM, Kirk H. wrote:

On Wednesday 26 April 2006 3:31 pm, Jake McArthur wrote:

Ruby: […] More powerful than Perl (IMHO), but not as concise.

I would argue that point. […]

Kirk H.

I was talking about the way people generally use the two languages:
Perl => quick hacks; Ruby => engineered solutions. Yes, if you
typically engineer your Perl code, then your engineered Ruby code
will probably be shorter.

  • Jake McArthur

Kirk H. wrote:

of it in Ruby, just to bask in it’s readability and it’s terseness. It was a

It could just be me, but I feel that the biggest difference is more
cultural vs technical. You can write long elegant Perl code and you can
write short obfusticated Ruby code. (If you were talking about OLD Perl
obviously this is a different argument, but current 5.5+ is entirely
capable.)

Alan M wrote:

At this phase I am thinking to upgrade my programming language to either
Python or Ruby.

I use both. I like them both. IMO, Ruby is more flexible than Python.
They go about things differently (Python is much more explicit in its
syntax), but the end result of scripts written in either language are
the same.

Python is more popular and has more thrid party modules/libraries, but
Ruby is catching up. If Rite and YARV ever become a reality and better
Windows support comes to Ruby (I believe it will), I can see Ruby
catching up to Python much more quickly.

Personally, I find Ruby more enjoyable to write and read than Python,
but you may not. You’ll do fine with either (or both) of them in sys
admin scripting :slight_smile:

Best of luck,
Brad

On 4/26/06, James Edward G. II [email protected] wrote:

On Apr 26, 2006, at 4:31 PM, Jake McArthur wrote:

More powerful than Perl (IMHO), but not as concise.

Could you given a small example program in Perl that is lengthier in
Ruby? (Just curious.)

I don’t have any of my early Perl to Ruby conversions anymore (and
they were done under NDAs anyway). But I also remember that my
Ruby solutions tended to be shorter – mostly because more powerful
approaches (like map and grep) clicked with me in Ruby but didn’t
in Perl.

James Edward G. II


thanks,
-pate

Hi –

On Thu, 27 Apr 2006, James Edward G. II wrote:

On Apr 26, 2006, at 4:31 PM, Jake McArthur wrote:

More powerful than Perl (IMHO), but not as concise.

Could you given a small example program in Perl that is lengthier in Ruby?
(Just curious.)

s/// stuff is shorter than sub(//,‘’) stuff.

David


David A. Black ([email protected])
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

“Ruby for Rails” PDF now on sale! Ruby for Rails
Paper version coming in early May!

On Wednesday 26 April 2006 3:47 pm, Stuart S. wrote:

It could just be me, but I feel that the biggest difference is more
cultural vs technical. You can write long elegant Perl code and you can
write short obfusticated Ruby code. (If you were talking about OLD Perl
obviously this is a different argument, but current 5.5+ is entirely
capable.)

But that’s not what I am talking about. It had nothing at all to do
with a
cultural difference when I was comparing the two languages, and
everything to
do with the languages. I was largely rewriting Perl code that was
written to
be terse but readable/maintainable. There were isolated examples of a
small
piece of Perl being shorter than equivalent Ruby, but for any given body
of
code longer than a few lines, almost without exception, my newbie-Ruby
(i.e.
I wasn’t very sophisticated with my use of the language) was shorter and
more
readable than Perl with equivalent functionality.

I had a directory of examples of this. It’s one of the things that
convinced
me that learning and using Ruby was a good thing to be doing.

Kirk H.

Great!

I am so excited and I canâ??t wait to learn Ruby.

The problem is that any single Ruby quick start code that I saw does
some AJAX web application :frowning:

What I need to do with Ruby is text file processing, file manipulations,
and query oracle database. Is there any tutorial for command line
application developers? Is it easy to query Oracle 10g with Ruby?

Where can download RedHat and Windows version of Ruby?

Sorry for asking so many question in one post!

I appreciate your help,
Alan

On Apr 26, 2006, at 5:06 PM, [email protected] wrote:

s/// stuff is shorter than sub(//,’’) stuff.

I don’t lose too much sleep over a couple of characters. I was
finishing for something significant, maybe an algorithm we could
improve… :wink:

James Edward G. II

On Apr 26, 2006, at 5:14 PM, [email protected] wrote:

@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona
tsuJ";sub p{
@p{“r$p”,“u$p”}=(P,P);pipe"r$p",“u$p”;++$p;($q*=2)+=$f=!fork;map
{$P=$P[$f^ord
($p{$})&6];$p{$}=/ ^$P/ix?$P:close$}keys%p}p;p;p;p;p;map{$p{$}
=~/^[P.]/&&
close$}%p;wait until$?;map{/^r/&&<$>}%p;$_=$d[$q];sleep rand(2)
if/\S/;print

… This discussion is over.

On Thu, 27 Apr 2006 [email protected] wrote:

s/// stuff is shorter than sub(//,‘’) stuff.

plus

@P=split//,“.URRUU\c8R”;@d=split//,“\nrekcah xinU / lreP rehtona
tsuJ”;sub p{
@p{“r$p”,“u$p”}=(P,P);pipe"r$p",“u$p”;++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$})&6];$p{$}=/
^$P/ix?$P:close$}keys%p}p;p;p;p;p;map{$p{$}=~/^[P.]/&&
close$}%p;wait until$?;map{/^r/&&<$>}%p;$_=$d[$q];sleep
rand(2)if/\S/;print

is w_a_a_a_y shorted than the equivalent ruby.

Obfuscated Perl Program

:wink:

-a

On 4/26/06, Alan M. [email protected] wrote:

Great!

I am so excited and I can’t wait to learn Ruby.

The problem is that any single Ruby quick start code that I saw does
some AJAX web application :frowning:

You’re probably seeing a lot of Ruby on Rails tutorials, if you were
unaware
it’s a very popular web development framework for Ruby.

What I need to do with Ruby is text file processing, file manipulations,

and query oracle database. Is there any tutorial for command line
application developers? Is it easy to query Oracle 10g with Ruby?

I would recommend going out and buying a copy of Pragmatic Programmers
Programming Ruby 2nd Ed. The 1st Ed. is available online for free at
http://www.rubycentral.com/book/

I know Ruby-DBI supports Oracle (not sure about your specific version)
check
it out here http://ruby-dbi.rubyforge.org/

Where can download RedHat and Windows version of Ruby?

On Apr 26, 2006, at 8:09 PM, Michael G. wrote:

You’re probably seeing a lot of Ruby on Rails tutorials, if you
were unaware
it’s a very popular web development framework for Ruby.

You know, this Rails craze is scaring me. I love Rails, but Ruby is
getting a lot of associations with web applications now, and that
might sway other potential programmers that aren’t into that sort of
thing from checking it out.

  • Jake McArthur

On 4/26/06, Jake McArthur [email protected] wrote:

You know, this Rails craze is scaring me. I love Rails, but Ruby is
getting a lot of associations with web applications now, and that
might sway other potential programmers that aren’t into that sort of
thing from checking it out.

I agree.

What is ironic is that before Rails the phrase “Ruby and web
applications” was not something that was very talked about. In fact we
complained about not having a good web app framework. Watch out what
you wish for…

Ryan

P.S. Not that I’m really complaining…Rails is helping me move out of
Java hell.

On 4/26/06, Alan M. [email protected] wrote:

What I need to do with Ruby is text file processing, file manipulations,
and query oracle database. Is there any tutorial for command line
application developers? Is it easy to query Oracle 10g with Ruby?

Very nice OCI8 library for Ruby here:
http://www.jiubao.org/ruby-oci8/

Traditional lame code sample:

#/usr/bin/env ruby
require ‘oci8’
connection = OCI8.new ‘username’, ‘password’, ‘someSID’
count = connection.exec(“select col1, col2, col3 from some_table”) do
|row|

row is an array containing the value of col1, col2, and col3

puts row.join(‘,’)
end
puts “Printed #{count} rows in all.”