in reply to Autovivification in perl

This is the use, which would you rather have to type?
use Data::Dump qw/ dd /; { my @blah; $blah[0] = []; $blah[0][$i] = []; $blah[0][$i][$j] = []; $blah[0][$i][$j][$k] = {}; $blah[0][$i][$j][$k]{life} = 42; dd( \@blah ); } { my @blah; $blah[0][$i][$j][$k]{life} = 42; dd( \@blah ); } __END__

The same in javascript* where they don't have autovivification

$blah[0] = new Array(); $blah[0][$i] = new Array(); $blah[0][$i][$j] = new Array(); $blah[0][$i][$j][$k] = new Object(); $blah[0][$i][$j][$k].life = 42;

* instead of new Array() you can type [] (like in Perl ), and instead of new Object() you can type {} (like in perl)

when we use this autovivification in perl.

All the time :)

See Data::Diver and Re: Parsing SOAP::Lite results (with Data::Diver), and Lexical scoping like a fox, Variable Scoping in Perl: the basics, ... autovivification, autovivification, The Bad, the Ugly, and the Good of autovivification, References quick reference, autovivification, autovivification, undefined value as an ARRAY reference sometimes ok, What does Autovivify mean?, Should perl auto vivify here?, TLC: Programming: Perl: Autovivification : What is it and why do I care?, , perlreftut#Making References , references quick reference

Modern Perl

Reference Coercion

Using a dereferencing operation on a non-reference turns that value into a reference (Autovivification, pp. 62) is handy when manipulating nested data structures (Nested Data Structures, pp. 61):

  • Comment on Re: Autovivification in perl (less clicks of the keyboard to create arbitrarily complex data structures)
  • Select or Download Code