my @arr = ();
is a cluttered, inefficient way of writing
my @arr;
What it does: It creates a new empty lexically-scopped array named @arr
.
Lexically-scoped means @arr
is only visible (i.e. can only be used) within the inner-most curlies (or file) that contains it.
Assigning an empty list to array empties it, but newly created arrays are guaranteed to be empty already.
my @arr = qw( A B C D );
is equivalent to
my @arr = split(' ', q( A B C D ));
It's a convenient (i.e. shorter) way of writing
my @arr = ( 'A', 'B', 'C', 'D' );
What it does: It creates a new lexically-scopped array named @arr
, and assigns four strings (A
, B
, C
and D
) to it.
You'd get the same result from
my @arr;
$arr[0] = 'A';
$arr[1] = 'B';
$arr[2] = 'C';
$arr[3] = 'D';
(@arr, @arr = ( ))
makes no sense. It amounts to @arr = ()
.
my @arr = qw (A B C D); my @arr = ();
makes no sense. It amounts to my @arr;
.