On 8/18/11 Thu  Aug 18, 2011  7:51 AM, "Zak" <b.zaryc...@gmail.com>
scribbled:

> can you reference elements of an array/hash from within that array/
> hash for example would
> 
> @array=(A, B, C, D, $array[0], E, F)
> 
> fly?

Try it out. See what you get.

The above will not set the fifth element of @array to 'A', however, if that
is what you are trying to do. What will actually happens depends upon the
state of @array when this statement is executed.

The left-hand side of the assignment statement is a list, which will be
created as the first part of the statement execution. The list will then be
assigned to the array variable @array. The value of the fifth element of the
list will be assigned from the current value of the fifth element of @array.
If this is the first time @array has been assigned a value, then that
element will be null. If, in addition, you have 'use strict;' and have not
declared @array previous to this statement, you will get a compilation error
("Global symbol "@array" requires explicit package name at ...").

Do this instead:

my @array = qw( A B C D X E F );
$array[4] = $array[0];



-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to