in reply to Re^2: Add new data to array
in thread Add new data to array
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: <%-{-{-{-<
|
|---|