Here is an example.

In Ruby when you write x[foo] then Ruby calls the [] method on x with foo as an argument. Unless that is followed by an = in which case you call the []= method instead. So by providing those two methods, that piece of syntax is supported. And lots of core data types provide those two methods.

The result is that x[foo][bar][baz] might be the equivalent of $x[$foo][$bar][$baz] in Perl, or perhaps $x{$foo}{$bar}{$baz} in Perl, or perhaps $x{$foo}[$bar]->($baz) - and that is before you get into user-defined types!

In Perl the first one of those might create anonymous arrays, and the second might create anonymous hashes. In Ruby if you're accessing something that isn't there it has to be an error because there aren't enough syntactical hints around to guess what the programmer meant.

The flip side of that is that in Ruby to create something that, say, acts like a hash backed by a dbm, all that you have to do is define a class with those two methods, and make those methods do the right thing. If you also want to add a locking method for your dbm class, you just have to add the locking method. And it works.

tie in Perl only looks impressive because Perl's syntax is constantly setting up expectations about what the syntax does. Therefore causing that syntax to do something other than what it looks like it should do is very surprising. Ruby's syntax sets no such expectations, and so making the syntax do something new does not look impressive. Until you sit down and realize that making something sophisticated look routine is a pretty impressive accomplishment!


In reply to Re^3: Perl 5's greatest limitation is...? by tilly
in thread Perl 5's greatest limitation is...? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.