Subject: | Incorrect behaviour when some elements of array are missing |
use strict;
use strict;
use warnings;
use JSON;
my $ta = []; # test array
$ta->[0] = 0;
#$ta->[1] = 1; # we skip this element so it doesn't exists
$ta->[2] = undef; # but this element will exists with undefined value
$ta->[3] = 3;
for my $i (0 .. 3) {
printf ("existence of element $i %s\n", exists($ta->[$i]) );
}
print JSON->new->utf8(1)->encode( $ta ), "\n";
####
got
existence of element 0 1
existence of element 1
existence of element 2 1
existence of element 3 1
[0,null,null,3]
### IMHO expected
existence of element 0 1
existence of element 1
existence of element 2 1
existence of element 3 1
[0,,null,3]
###########
Undefined and missing elements are not the same