These are some things you should understand about Perl datastructures (and if you learn something there, maybe it's time to read all the perltut* from the perl distribution).
so:
defined(@data) is a perl non-sense@my_array = undef actually means $my_array[0] = undef@my_array = (undef, 'a') actually means $my_array[0] = undef;
$my_array[1] = 'a';@dictqw< foo bar > = (undef, 'a') actually means $dictfoo = undef;
$dictbar = 'a';@dictqw< foo bar > = @dictqw< bar foo > exchanges the values of $dictfoo and $dictbar
if you want to know if the array is empty, just use a scalar context
if ( @data )
if ( %dict )
$#my_array is the bound, not the size @my_array == 1+ $#my_array $my_array[ $#my_array ] # is actually
$my_array[ -1 ]
$my_array[ $#my_array -1 ] # is actually
$my_array[ -2 ]call a sub using & is a way to share @_ with the caller! (very powerfull but tricky for most of us). If you don't understand or don't want that, please don't call using &.
remember for and map loops are side-effects, even if you declare a variable
@data = ( 1..3 );
for my $d ( @data ) $d++
# so @data is now 2,3,4 $dictkey = undef;
exists $dictkey # true
defined $dictkey # false
0 # false
1 # true
'0' # false (converted to 0)
'1' # true (converted to 1)
'' # false (empty string)
length '0' # true (converted to 1)If you challenge perl on nested datastructures, it will create everything needed to anwser correctly so:
if ($my_hash'level1''level2') ...needed to anwser correctly so even if $my_hashlevel1 was empty, it will be filled with a level2 => undef hashref in the mean to reply false.