I have 7 arrays that are defined in the following manner:
my @array1 = ();
..
my @array7 = ();
and then:
$array1[0] = "text goes here";
..
$array7[0] = "text goes here";
There are about 25 elements) in each of the seven arrays, that is, $array1[0] to $array1[24]. I need to frequently change the content of these arrays in various scripts. And sometimes, because the order of the arrays is essential, I need to rearrange the order of the array index or delete the elements at a position. This is a real pain in the ass, as I need to change the index of all subsequent arrays. Just to make it clear, if I delete array1[12], then I need to change $array1[13] to $array1[12] and that for all 7 arrays and for all subsequent index positions (or move the content of array1[13] to array1[12], etc.)
So my question is, is it possible to impute the index of the arrays so that I could switch around the arrays position without having to correct each array index afterwards? Something like this:
$array1[$_] = "text 1 goes here";
..
$array7[$_] = "other text 1 goes here";
and then:
$array1[$_] = "text 2 goes here";
..
$array7[$_] = "other text 2 goes here";
where $_ would be replaced by 1 for the first index of each of the 7 arrays and by 2 for the next element of each of the 7 arrays… (up to 24 elements).
Is there a solution to this problem other than using an hash and Tie::Hash?
EDIT
ok, let me clarify. I am looking for a script maintenance solution, no for a solution about the output of the script. I need to change the script myself (by hand) frequently and I do not want to change the numbers indexing all 24 positions of all 7 arrays by hand whenever I change something in these arrays. So my question was, is there a way to have the script impute the numbers indexing all positions of all arrays?
Using push as mvp was suggesting would be a proper solution. Are there any other solutions that could involve loops or something rather than using push 7X24 times?
You can use this approach:
You can even do this (little bit nasty because of dynamic variables):