Using grep on undefined array

James Laver james.laver at gmail.com
Wed Aug 14 16:26:50 BST 2013


On Wed, Aug 14, 2013 at 1:59 PM, Matt Lawrence <matt.lawrence at virgin.net> wrote:
>
> man perlglossary:
>
> autovivification
>
> A Graeco-Roman word meaning “to bring oneself to life”. In Perl, storage
> locations (lvalues) spontaneously generate themselves as needed, including
> the creation of any hard reference values to point to the next level of
> storage. The assignment $a[5][5][5][5][5] = "quintet" potentially creates
> five scalar storage locations, plus four references (in the first four
> scalar locations) pointing to four new anonymous arrays (to hold the last
> four scalar locations). But the point of autovivification is that you don’t
> have to worry about it.

perlglossary is wrong. It doesn't only occur as an lvalue but can
occur by access as well.

I'm actually surprised that noone has mentioned the 'autovivification'
pragma ('unpragma'?) by now in a fairly long thread.

use strict;
use warnings;
no autovivification;
my %foo;
my $bar = $foo{bar}[1];
die("fail 1") if %foo; # does not die because autovivification was suppress
use autovivification;
$bar = $foo{bar}[1];
die("fail 2") if %foo; # does die, we turned off suppression


James



More information about the london.pm mailing list