Don’t use “my” again and again to declare $rock[0], $rock[1] etc. Declare the array once (@rocks) once and use it.
you need to declare my @rocks and then not use my any more when referring to $rocks[xxx].
If you don’t know how many elements are going to be in there, you can use push to add new elements into the (initially 0-sized) array.
- from StackOverflow.com
#!C:\Perl\bin\perl.exe # activePerl 5.8 based use strict; # enabled use warnings; my @rocks; ($rocks[0], $rocks[1]) = qw/Hello World/; $rocks[2] = 'Tom'; $rocks[3] = 'Cat'; print $rocks[0]; print $rocks[1]; print $rocks[2]; print $rocks[3];