From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2003-06-12T14:39:38+09:00 Subject: Re: Ruby advantages over Perl In article <20030612022421.GZ22846@ouroboros.anu.edu.au>, Iain Truskett wrote: >* Phil Tomson (ptkwt@shell1.aracnet.com) [12 Jun 2003 11:58]: > >[...] >> 1) Built-in types like Array seem to have more methods that work on them >> than Perl's. ie. you can do this out of the box in Ruby, but I don't >> think you can in Perl: > >> a = ['a','b','c','d','e'] >> b = a - ['c'] >> #b => ["a", "b", "d", "e"] > >There's no operator overloading of this sort, no. Of course, >this particular task could be viewed as a convenient fa�ade >to the find and reject methods, which perl has as the grep >function. > > @b = grep { $_ != 4 } @a; > b = a.reject { |e| e == 4 } I didn't mean to imply it was impossible in Perl, but it's much easier and more convenient in Ruby. > >[...] >> 3) any type of object can be used as a key in a Ruby hash (Perl can >> only use strings as keys). > >Although it should be noted that references will be happily >stringified if used as keys and that there is a core module >Tie::RefHash that lets you use 'real' references as keys. > >[...] Fair enough. >> 5) yield and code blocks > >These are trivial to implement, you just end up with a few >more keywords. I'm a bit skeptical that it would be trivial to implement yield in Perl. ....not saying it would be impossible to implement, but I'm thinking it wouldn't be trivial. > >Basically, the main difference I usually see between Perl >and Ruby is that Ruby just gives you less 'noise'. Take away >various characters from a Perl program and you approach the >Ruby one. Start restructuring your code to be more Rubyish, >you lose even more. > >You can do anything in Perl that you can in Ruby, it's just >that some things may require you to pull in a module or >write a few more characters. True. Languages influence how we think about problems, and while you can program in a Perlish way in Ruby (a lot of us started out that way ;-) it's probably more difficult (or it doesn't occur to the Perl programmer) to program in a Rubyish way in Perl. Phil