Q:

Perl: How do I declare empty array refs in a new hash?

I've got strict and warnings on, but it keeps complaining about the initialization of the following line:
$hash{$key} = ($row, [], [], [], '');

It warns for that single line:
"Useless use of private variable in void context"

"Useless use of anonymous list ([]) in void context" (3 times)

I am filling the data in later, but I want indexes 1, 2, 3 to be array references, and index 4 to be a string. I am accessing and filling the data like so:
$hash{$key}->[1]->[3] = 'Data';
$hash{$key}->[4] = $hash{$key}->[4] . 'More Data';

Obviously, I'm doing something wrong, but I'm not exactly sure how to make it right. (Also, I'm aware that that last line is redundant, could that also be summed up in a nicer way?)

A:

Elements of a hash can only be scalars, so you have to change your assignment to use the anonymous array constructor instead of parens:
$hash{$key} = [$row, [], [], [], ''];

See perldsc for more information.
The line:
$hash{$key}->[4] = $hash{$key}->[4] . 'More Data';

could be written:
$hash{$key}->[4] .= 'More Data';

And finally, unless you like them, the -> characters are implicit between subscript delimiters, so $hash{$key}->[1]->[3] means the same thing as $hash{$key}[1][3]

A:

I'm not quite sure what you are trying to do, but if you want to assign an array to a scalar value, you need to use brackets to create an anonymous array:
$hash{$key} = [$row, [], [], [], ''];

In your case, what you are attempting to do is interpreted as follows:
$row, [], [], [];
$hash{$key} = '';

Because you cannot assign a list of values to a scalar (single value variable). You can, like we did above, however, assign a reference to an anonymous array containing a list of values to a scalar.

