I have 2 empty arrays that I add items to using a for loop.
@main = (
"a 1 b 2 c 3 ",
"d 4",
"e 5 f 6 g 7 h 8",
"i 9 j 10",
);
@arr1 = (); #only gets the letters
#supposed to look like:
#(
#[a,b,c]
#[d]
#[e,f,g,h]
#[i,j]
#)
@arr2 = (); #only gets the numbers
#supposed to look like:
#(
#[1,2,3]
#[4]
#[5,6,7,8]
#[9,10]
#)
for($i=0;@main;$i+=1){
@line = split(/\s+/,shift(@main));
push(@arr1,[]);
push(@arr2,[]);
while(@line){
push(@arr1[$i],shift(@line));
push(@arr2[$i],shift(@line));
}
}
error:
Experimental push on scalar is now forbidden at index.pl line 29, near "))"
Experimental push on scalar is now forbidden at index.pl line 30, near "))"
It seems that @arr[$i] returns a reference to an array. How do I get this array and add items to it?