in reply to Re: Difference between exists and defined
in thread Difference between exists and defined
Your code example, the way you use Data::Dumper to show the contents of the array allows room for misinterpretation of what is realy happening here. I feel that a better code example is the following:
use strict ; use warnings ; use Data::Dumper ; my @ar ; $ar[0] = undef ; $ar[2] = 3 ; if ( exists $ar[0] ) { print "0 exists\n" ; } if ( exists $ar[1] ) { print "1 exists\n" ; } if ( exists $ar[2] ) { print "2 exists\n" ; } if ( exists $ar[3] ) { print "3 exists\n" ; } print Dumper(\@ar) ;
This prints:
0 exists 2 exists
As you can see element 0 DOES exists when it is explicitly set to undefined. Using Data::Dumper prints:
$VAR1 = [ undef, undef, 3 ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Difference between exists and defined
by thanos1983 (Parson) on Apr 16, 2019 at 10:52 UTC |