Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This is a two-part question. First, as a followup to the explanations in Array dereference in foreach(), where the whole point was that autovivification happens in lvalue context, does it seem counterintuitive to anyone else that the last of the following doesn't throw an error, especially when compared to the second-to-last example? (inspired by this thread from today)

$ perl -wMstrict -MData::Dump -e' @{$a->{list}} =(); dd $a' { list => [] } $ perl -wMstrict -MData::Dump -e' for (@{$a->{list}}) {}; dd $a' { list => [] } $ perl -wMstrict -MData::Dump -e' my @x = @{$a->{list}}; dd $a' Can't use an undefined value as an ARRAY reference at -e line 1. $ perl -wMstrict -MData::Dump -e' my $x = @{$a->{list}}; dd $a' Can't use an undefined value as an ARRAY reference at -e line 1. $ perl -wMstrict -MData::Dump -e' my $x = $#{$a->{list}}; dd $a' { list => [] }

Second, it has bothered me that there doesn't appear to be a central reference on autovivification. The perldocs only mention it in one or two sentences, mostly perlref, but there isn't a section heading anywhere, explaining it overall, that I can link to. There also doesn't appear to be anything in Tutorials either, all I could find so far is the SoPW Explaining Autovivication plus one or two other threads, but no central place where it is all explained. Unless I have missed something - does anyone happen to know?

Update: Thanks for the replies everyone!

Update 2: There are a couple more interesting cases having to do with autovivification and changes to scalar in Why doesn't this die with "Can't use an undefined value as an ARRAY reference"?".


In reply to Autovivification Oddity by haukex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-03-28 17:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found