Perl has a notable advantage for doing arbitrary data structures

I wonder if this advantage is due to autovivification or are there other reasons? AFAIK, autovivification is unique to Perl. A simple illustration of autovivification in Perl vs Ruby (taken from this old golf node) is:

$z[ 0][ 8] = 'o'; $z[ 1][11] = 'o'; $z[ 3][14] = 'o'; $z[ 5][15] = 'o'; $z[ 7][14] = 'o'; $z[ 9][11] = 'o'; $z[10][ 8] = 'o'; $z[ 9][ 4] = 'o'; $z[ 7][ 1] = 'o'; $z[ 5][ 0] = 'o'; $z[ 3][ 1] = 'o'; $z[ 1][ 4] = 'o'; print"@$_\n"for@z;

To emulate the Perl test program above in Ruby, you might try:

z=[] (z[ 0]||=[])[ 8] = 'o' (z[ 1]||=[])[11] = 'o' (z[ 3]||=[])[14] = 'o' (z[ 5]||=[])[15] = 'o' (z[ 7]||=[])[14] = 'o' (z[ 9]||=[])[11] = 'o' (z[10]||=[])[ 8] = 'o' (z[ 9]||=[])[ 4] = 'o' (z[ 7]||=[])[ 1] = 'o' (z[ 5]||=[])[ 0] = 'o' (z[ 3]||=[])[ 1] = 'o' (z[ 1]||=[])[ 4] = 'o' puts z.map{|i|(i||[]).join" "}
Note that, because Ruby does not autovivify, you must manually create the empty lists -- using the || operator in the test program above. Note further that 0 and "" evaluate to true in Ruby, so the Ruby || operator is closer to Perl's // "defined or" operator than its || "or" operator.

Update: As noted in brian_katzung's necropost reply below, you can autovivify nowadays in Ruby using his XKeys Gem. Some links:


In reply to Re^2: Honest question about Perl, Python and Ruby (autovivification) by eyepopslikeamosquito
in thread Honest question about Perl, Python and Ruby by madM

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.