Forum: Ruby Ruby for command line applications

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Alan M (Guest)
on 2006-04-27 01:21
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
Jake McArthur (Guest)
on 2006-04-27 01:34
(Received via mailing list)
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
Wilson B. (Guest)
on 2006-04-27 01:34
(Received via mailing list)
On 4/26/06, Alan M <removed_email_address@domain.invalid> 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.
pat eyler (Guest)
on 2006-04-27 01:43
(Received via mailing list)
On 4/26/06, Alan M <removed_email_address@domain.invalid> 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
Kirk H. (Guest)
on 2006-04-27 01:43
(Received via mailing list)
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.
James G. (Guest)
on 2006-04-27 01:43
(Received via mailing list)
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
Jake McArthur (Guest)
on 2006-04-27 01:46
(Received via mailing list)
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
Stuart S. (Guest)
on 2006-04-27 01:50
(Received via mailing list)
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.)
pat eyler (Guest)
on 2006-04-27 01:53
(Received via mailing list)
On 4/26/06, James Edward G. II <removed_email_address@domain.invalid> 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
brad (Guest)
on 2006-04-27 01:58
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 :)

Best of luck,
Brad
unknown (Guest)
on 2006-04-27 02:08
(Received via mailing list)
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 (removed_email_address@domain.invalid)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" PDF now on sale!  http://www.manning.com/black
Paper version coming in early May!
Kirk H. (Guest)
on 2006-04-27 02:08
(Received via mailing list)
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.
Alan M. (Guest)
on 2006-04-27 02:08

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 :(

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
James G. (Guest)
on 2006-04-27 02:14
(Received via mailing list)
On Apr 26, 2006, at 5:06 PM, removed_email_address@domain.invalid 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...  ;)

James Edward G. II
unknown (Guest)
on 2006-04-27 02:17
(Received via mailing list)
On Thu, 27 Apr 2006 removed_email_address@domain.invalid 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.

   http://perl.plover.com/obfuscated/

;-)

-a
Jake McArthur (Guest)
on 2006-04-27 02:33
(Received via mailing list)
On Apr 26, 2006, at 5:14 PM, removed_email_address@domain.invalid 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.
Michael G. (Guest)
on 2006-04-27 05:13
(Received via mailing list)
On 4/26/06, Alan M. <removed_email_address@domain.invalid> 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 :(


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?
Wilson B. (Guest)
on 2006-04-27 05:28
(Received via mailing list)
On 4/26/06, Alan M. <removed_email_address@domain.invalid> 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."
Jake McArthur (Guest)
on 2006-04-27 05:59
(Received via mailing list)
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
Ryan L. (Guest)
on 2006-04-27 07:07
(Received via mailing list)
On 4/26/06, Jake McArthur <removed_email_address@domain.invalid> 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.
John Brookes (Guest)
on 2006-04-27 17:37
(Received via mailing list)
How to unsubscribe?
No directions at bottom of each message.
Matthew M. (Guest)
on 2006-04-27 17:42
(Received via mailing list)
That's because they're at the top, in the headers.

List-Unsubscribe: <mailto:removed_email_address@domain.invalid?body=unsubscribe>
Dean W. (Guest)
on 2006-04-27 18:27
(Received via mailing list)
> I was talking about the way people generally use the two languages:
> Perl => quick hacks; Ruby => engineered solutions. ...

I find that if I have non-trivial structured data to manage, I've
crossed the threshold where I want Ruby's better OO support and more
"literate" Hash and Array representations. Perl's equivalents, while
perhaps more concise, become harder to understand and use. Plus, I
love playing with blocks ;)

dean

--
Dean W.
http://www.aspectprogramming.com
http://www.newaspects.com
http://www.contract4j.org
John G. (Guest)
on 2006-04-27 18:40
(Received via mailing list)
On 4/27/06, Matthew M. <removed_email_address@domain.invalid> wrote:
> That's because they're at the top, in the headers.
>
> List-Unsubscribe: <mailto:removed_email_address@domain.invalid?body=unsubscribe>
>
>
> On 4/27/06, John Brookes <removed_email_address@domain.invalid> wrote:
> > How to unsubscribe?
> > No directions at bottom of each message.
>
>

The main Ruby mailing lists page (
http://www.ruby-lang.org/en/20020104.html ) gives brief instructions:

|
| To unsubscribe from a list, send a mail which body is "unsubscribe" to the
| controller address.
|

Though, just to clean that up, it could be changed to read
something like:

}
} To unsubscribe from a given list, send an email to that mailing
} list's controller address. The body of that email should contain
} only the word "unsubscribe". It doesn't matter what the subject
} line is.
}
Charlie B. (Guest)
on 2006-04-27 18:52
(Received via mailing list)
> I find that if I have non-trivial structured data to manage, I've
> crossed the threshold where I want Ruby's better OO support and more
> "literate" Hash and Array representations. Perl's equivalents, while
> perhaps more concise, become harder to understand and use. Plus, I
> love playing with blocks ;)
>
> dean


    I agree completely, I began converting a small time keeper comand
line app I wrote in perl to keep track of my hours over to ruby as a way
of learning ruby.  I quickly began adding new features because the
object model makes that so easy.  That said, I still "enjoy" creating
reports in perl over ruby.  Probably because I've written so many more
in perl.

Charlie B.
www.recentrambles.com
John G. (Guest)
on 2006-04-27 19:36
(Received via mailing list)
On 4/26/06, Alan M <removed_email_address@domain.invalid> wrote:
> would be a better choice for me Perl or Ruby?
>
> Thank you,
> Alan
>

They're both good choices. I'm fairly new to Ruby, but here's my 2
cents.

Plusses for Python:
- Tends to be a consistent language (not *too* many ways to do the same
thing).
- Good library support.
- Good written docs (command-line pydoc docs are lacking though, IMO).
- Easily embeddable.

Minuses for Python:
- OO features seem a little trickier to me than Ruby's (bound vs.
unbound methods, class vs. static vs. plain vanilla methods).
- Some Python snobbishness in the community (just my opinion). Though,
the majority of Pythonistas are friendly and helpful.
- They put their docstrings *below* the thing they're documenting
instead of above it, where nature of course intended. ;)
- Personally, not fond of the whitespace-dependent code formatting
(though many many folks claim they get used to it quickly).

Plusses for Ruby:
- Ruby seems a little more tailored for admin work than Python (since
Ruby has built in regexes, easy stdin/stdout)
- RDoc (documentation for your scripts comes right from plain old
comments above the thing they're documenting).
- Personally, I prefer its (Perl-like) string handling to Python's.

Minuses for Ruby:
- Lack of docs (good printed books though)
John G. (Guest)
on 2006-04-27 19:43
(Received via mailing list)
On 4/27/06, John G. <removed_email_address@domain.invalid> wrote:
> > Considering the fact that I won't develop any web application, Which one
> Plusses for Ruby:
> - Ruby seems a little more tailored for admin work than Python (since
> Ruby has built in regexes, easy stdin/stdout)
> - RDoc (documentation for your scripts comes right from plain old
> comments above the thing they're documenting).
> - Personally, I prefer its (Perl-like) string handling to Python's.
>
> Minuses for Ruby:
> - Lack of docs (good printed books though)
>

By the way, there are, of course, other plusses for Ruby that are
relevant if you're looking at it for other uses besides system
administration.

Also, Ruby's a very consistent language too (dunno why I only
mentioned this for Python above -- they're both pretty
self-consistent).
Alex P. (Guest)
on 2006-04-28 01:02
(Received via mailing list)
Alan M wrote:
> 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.
>
>
I'm new to ruby but have years of experience with perl and python. I
generally perfer python over perl. But for oneliners and a lot of
sysadmin scripting I've always felt that perl really outshines python.

alex
M. Edward (Ed) Borasky (Guest)
on 2006-05-03 20:57
(Received via mailing list)
Alan M wrote:
> would be a better choice for me Perl or Ruby?
>
Well, I don't know anything about Python and not a whole heck of a lot
about Ruby. I've been using Perl for fairly complex "scripts" for almost
ten years now. Like another poster on this thread, I got tired of trying
to manage large "awk" scripts and wanted a language that made it at
least possible to write structured readable programs. That turned out to
be Perl 4.

If I were starting this project or set of projects today, I'd use Ruby.
It's much better designed for objects than what's been tacked on to
Perl. I don't have any pressing need to rewrite my few thousand lines of
Perl into Ruby (or Python), and what I don't do in Perl is usually
number crunching that I do in R.

So questions for you:

1. Do you just want to learn a new language, or is there something
you've found Perl weak at?

2. Is readability of your code by others important? If so, would these
others be better off if you stuck with Perl, or migrated to Python or
Ruby?

3. Have you looked at Perl 6? I must admit I haven't, and really don't
plan to. I'm happy with the current mix of Perl 5 (with my Perl 4 coding
style) and R, although there is one application I have coming up that's
a natural fit for Rails, and if I can sell it to the bean counters and
nay-sayers, that's what I plan to use.
> Thank you,
> Alan
>
>

--
M. Edward (Ed) Borasky

http://linuxcapacityplanning.com
Eric A. (Guest)
on 2006-05-03 21:09
(Received via mailing list)
I think the consistency comes down to how many
different ways there are to do things. That makes
it more difficult to master the idioms, because
different code does similar things in different ways.

But there is a /huge/ plus for Ruby that is lurking
in the background. After spending the weekend at the
SDForum's Ruby conference, the meta-message for me
was that Ruby was great at building a /language/
geared towards solving a particular set of problems.

In standard terminology, they're known as Domain Specific
Languages. But I prefer to think of them as Design
Solution Languages.

Not since Forth have I seen a language in which it
was so easy to create a problem-specific vocabulary.
I used to wish for a Forth with C-style syntax. (I
didn't know enough to wish for OO-ness back then.)
It turns out that Ruby is it.

So my pick would be Ruby for the promise of huge
vistas of opportunity that will open up once you scale
the learning curve and reach the peak of the mountain.

(When I manage to get there, I'll tell how the view is.)
:_)
Garance A Drosehn (Guest)
on 2006-05-03 21:10
(Received via mailing list)
On 4/26/06, Alan M <removed_email_address@domain.invalid> wrote:
> 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.

I started to use perl for scripting maybe 10 to 12 years ago, when I
finally decided that I was trying to force 'awk' to do things it was
never meant to do.  I wrote a lot of useful sysadmin-type programs
in perl (reading log files, summarizing data, etc).  But many of those
scripts were written in bits-and-pieces.  I start out needing a 3-line
perl script for some simple task.  Then a week later I need to add
something else.  Then I realize I could use the same script on two
different log files if I just made a few more changes.  Before long,
my initial 3-line perl script is up around 700 lines.  And, well, it's a
mess.  It's a mess because it was never designed to be a 700-line
program, it was built up a few dozen lines at a time, over many
weeks or months.

When doing the same kind of scripts in ruby, I found that I do a
much better job of re-factoring the program as I added more
features to it, or as I found out that the data I needed to process
looks nothing like I was told it was going to look like.  I *could*
write a good perl script if I started out with a fixed goal, and
stuck to whatever that original goal was, but that almost never
happens to me...

I used to do some Objective-C programming under NeXTSTEP,
and I found that the object-oriented support in ruby fits very
well with how my mind thinks.  I've looked over python a few
times, and I know some excellent sysadmins who use python
for their work, but python just never quite caught my interest.
I'm not sure why.  The usual complaint about python is the
whitespace-requirements that it has, and actually that does
not bother me at all.  But for some reason I found ruby much
more compelling to the way that I think than I found python
to be.
Christian N. (Guest)
on 2006-05-03 21:11
(Received via mailing list)
Eric A. <removed_email_address@domain.invalid> writes:

> Not since Forth have I seen a language in which it
> was so easy to create a problem-specific vocabulary.
> I used to wish for a Forth with C-style syntax. (I
> didn't know enough to wish for OO-ness back then.)
> It turns out that Ruby is it.

.oO(And that's probably the only thing Ruby and Forth have in common..
}:-))
This topic is locked and can not be replied to.