in reply to Re: Sort multidimensional array by third item
in thread Sort multidimensional array by third item
for my $line (@line_array) { push(@item_array, [split(/\s/, $line)]); }
If you want to use an explicit temporary storage array, you could use a variable that is scoped to the loop using my. This way, each iteration will create a new array with the same name, so each reference will be different.
for my $line (@line_array) { my @hold_array = split(/\s/, $line); push(@item_array, \@hold_array); }
Note I've swapped to Foreach Loops syntax to avoid possible indexing errors.
I also note you use our a lot. Each time you do that, you are creating a global variable. Is there some reason you want to do that? Likely, you should be using my instead.
|
|---|