WRT this code, because  $add_ins[0] is a hash reference (@add_ins is an array of hash references) and so  $add_in would become (by autovivification) a reference to an array holding a single element: a hash reference. The expression  $add_in->{name} would then have to become  $add_in->[0]{name} which would be possible, but a useless complication.

Update 1: Normally, a statement like
    my @$add_in = $add_ins[0];
would be written
    my @$add_in = ($add_ins[0]);
using parentheses to make the RHS a proper list, but in the special case of single-element array assignment, Perl allows the parentheses to be dispensed with. In
    my $add_in = ();
the parentheses have no effect; the statement is equivalent to
    my $add_in;

Update 2: BillKSmith covers a point which I neglected to mention: the statements
    my $add_in = ();
    my @$add_in = $add_ins[0];
are syntactically incorrect due to the use of the my declarator in the second statement. However, if this operator is removed, what's left is code that can be made to compile and to run without warnings and to work, albeit IMHO in an ugly, confusing and inefficient manner as discussed above.

c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "my @add_ins = ({ qw(foo bar) }, { qw(biz boz) }); ;; my $add_in = (); @$add_in = $add_ins[0]; dd $add_in; print $add_in->[0]{'foo'} " [{ foo => "bar" }] bar


Give a man a fish:  <%-{-{-{-<


In reply to Re^3: Add new data to array (updated) by AnomalousMonk
in thread Add new data to array by Anonymous Monk

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.