in reply to Initialization of arrays
Although the value is not defined (undef), it still exists.#!/usr/bin/perl use strict; use warnings; my @x = (); $x[10] = 1; @x[1..3] = (1,1); $x[5] = undef; for(my $y=0; $y!=@x; $y++) { if(exists($x[$y])) { print "$y exists"; } if(defined($x[$y])) { print "\t$y defined"; } print "\n"; } prints: 1 exists 1 defined 2 exists 2 defined 3 exists 5 exists 10 exists 10 defined
|
|---|