EnglishDeutschFrançaisEspañolPortuguêsIndonesian日本語한국어简体中文繁體中文PolskiTürkçe

Von Perl zu Ruby

Perl is awesome. Perls docs are awesome. The Perl community is awesome. However, the language is fairly large and arguably complex. For those Perlers who long for a simpler time, a more orthogonal language, and elegant OO features built-in from the beginning, Ruby may be for you.

Similarities

As with Perl, in Ruby,...
  • youve got a package management system, somewhat like CPAN (though its called RubyGems )
  • regexes are built right in. Bon apptit!
  • theres a fairly large number of commonly-used built-ins.
  • parentheses are often optional
  • strings work basically the same.
  • theres a general delimited string and regex quoting syntax similar to Perls (looks like %q{this (single-quoted)} , or %Q{this (double-quotish)} , and %w{this for a single-quoted list of words} . You %Q|can| %Q(use) %Q^other^ delimiters if you like).
  • youve got double-quotish variable interpolation, though it "looks #{like} this" (and you can put any Ruby code you like inside that #{} ).
  • shell command expansion uses `backticks`.
  • youve got embedded doc tools (Rubys is called rdoc).

Differences

Unlike Perl, in Ruby,...
  • you dont have the context-dependent rules like with Perl.
  • a variable isnt the same as the object to which it refers. Instead, its always just a reference to an object.
  • although $ and @ are used as the first character in variable names sometimes, rather than indicating type, they indicate scope ( $ for globals, @ for object instance, and @@ for class attributes).
  • array literals go in brackets instead of parentheses.
  • composing lists of other lists does not flatten them into one big list. Instead you get an array of arrays.
  • its def instead of sub .
  • theres no semicolons needed at the end of each line. Incidentally, you end things like function definitions, class definitions, and case statements with the end keyword.
  • objects are strongly typed. Youll be manually calling foo.to_i , foo.to_s , etc., if you need to convert between types.
  • theres no eq , ne , lt , gt , ge , nor le .
  • theres no diamond operator. You usually use IO. some_func instead.
  • the fat comma is only used for hash literals.
  • theres no undef . In Ruby you have nil . nil is an object (like anything else in Ruby). Its not the same as an undefined variable. It evaluates to false if you treat it like a boolean.
  • when tested for truth, only false and nil evaluate to a false value. Everything else is true (including 0 , 0.0 , and "0" ).
  • theres no PerlMonks . Though the ruby-talk mailing list is a very helpful place. And weve also got a wiki and a faq .

rubyforge.org rubyforge.org rubyforge.org tryruby.hobix.com rubyforge.org rubyforge.org forum.ruby-portal.de radiantcms.org