http://qs321.pair.com?node_id=1232633


in reply to Difference between exists and defined

Hello milanpwc,

From the documentation exists:

A hash or array element can be true only if it's defined and defined o +nly if it exists, but the reverse doesn't necessarily hold true.

So why you are expecting to be true on not defined elements (not existing elements)?

Is it more clear or still confusing?

Also take notice from documentation:

exists may also be called on array elements, but its behavior is much +less obvious and is strongly tied to the use of delete on arrays. WARNING: Calling exists on array values is strongly discouraged. The n +otion of deleting or checking the existence of Perl array elements is + not conceptually coherent, and can lead to surprising behavior.

Update: I think I understand why you are confused. You are not assigning to all elements in the array the value 2. Only to one element. See below:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @array; $array[3] = 2; print Dumper \@array; __END__ $ perl test.pl $VAR1 = [ undef, undef, undef, 2 ];

BR / Thanos

Seeking for Perl wisdom...on the process of learning...not there...yet!