Your understanding is correct.
The []
always creates an array reference, and references always are scalars. Here, my @arr = []
(or equivalently: my @arr = ([])
) creates an array @arr
with the first element being an array reference.
Scalars are never context-dependent! Context only matters for
- hash or array variables:
@foo
and%foo
- subroutine calls, as a call propagates the current context and can be queried via
wantarray
. Subroutines may therefore behave differently in various context. - operators, as some operators like
,
or..
are entirely different depending on context.