in reply to Question: Is undef a valid argument?
$scalar, $array[$index] and $hash{$key} always evaluate to a scalar. Should the variable or element not exist, that scalar is undef.
$ perl -le'@x = $scalar; print 0+@x; print $x[0] // "[undef]"' 1 [undef] $ perl -le'@x = $array[0]; print 0+@x; print $x[0] // "[undef]"' 1 [undef] $ perl -le'@x = $hash{foo}; print 0+@x; print $x[0] // "[undef]"' 1 [undef]
|
|---|