Home > Articles > Web Development > Perl

  • Print
  • + Share This
Like this article? We recommend

Like this article? We recommend

Autovivification and Lists

The same thing occurs with an array reference as with the hash reference. In the following snippet, Perl sees that $aref->[2] was being used as an array reference (attempting to get the first element of the non-existent reference), and autovivified it. When done, $aref will contain three elements, the last one being an empty list.

    01: my $aref = [[1, 2, 3], [one, two, three]];
    02: print @$aref . "\n"; # prints 2
    03: print $aref->[2][1]; # prints nothing, since it doesn't exist
    04: print @$aref . "\n"; # prints 3
  • + Share This
  • 🔖 Save To Your Account