Can you cite your sources? Where did you learn about autovivification? in perl?

You offered these two snippets but they're not perl :)

$ perl -le " my $bar[396]++; " syntax error at -e line 1, near "$bar[" Execution of -e aborted due to compilation errors. $ perl -le " my $bar[396]; " syntax error at -e line 1, near "$bar[" Execution of -e aborted due to compilation errors.

$foo is a named variable, it has a name, it doesn't need to be autovified, it exists by virtue of being named, just like @bar is a named variable, it has a name, it doesn't need to be autovivified, it exists by virtue of being named. By default all variables are global.

When you add my $foo; my @bar; you declare $foo and @bar to be lexical variables (not global)

it also has the side effect of satisfying use strict 'vars'; by letting it know you didn't make a typo, that you intended to have variables named $foo and @bar

neither is related to what we call autovivification ; autovivification is about using references to create complex data structures with less clicks of the keyboard

autovivification does not refer to declaring (naming) variables, it is a feature that saves you typing, it saves you from having to write  $foo[6] ||= []; $foo[6][6]=6; you can simply write  $foo[6][6] = 6; and  $foo[6] autovivifies/ becomes an arrayref

explicit, assigning an array ref to  $foo[6] ||= []; $foo[6][6]=6;

implicit, autovivifying an array ref, treat it like an array ref, it becomes an array ref  $foo[6][6] = 6;

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?, Tutorials ...


In reply to Re^6: Occurence List (more on autovivification) by Anonymous Monk
in thread Occurence List by Hopfi

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.