I have three arrays that need to be stored together for future use. Each array is related to each other, and every array element per position is meant to be matched together. The arrays elements orders will always be correct, but beyond that, there is no easy way to discern the correct order once lost.
How can I combine these arrays together without losing their original order?
I am assuming that an array of hashes is the best way to go, but, please let me know if I'm wrong in that assumption.
Example Arrays:
my @numbers = (5,2,7,32,9);
my @letters = qw(z b t t c);
my @words = qw(tiny book lawn very dance);
Example end result.
my @combined_arrays = (
{
'number' => '5',
'letter' => 'z',
'word' => 'tiny',
},
{
'number' => '2',
'letter' => 'b',
'word' => 'book',
},
{
'number' => '7',
'letter' => 't',
'word' => 'lawn',
},
{
'number' => '32',
'letter' => 't',
'word' => 'very',
},
{
'number' => '9',
'letter' => 'c',
'word' => 'dance',
},
);
my @combined_arrays = (\@numbers, \@letters, \@words )? ormy @combined_arrays = ([@numbers], [@letters], [@words] )if you need to make a copy...([5,'z','tiny'], ...), if you want to group them by position. For how to create either see this recent page (near duplicate).number,letter,wordthen there is no confusion. I also recommend an array of arrays for simplicity and economy of space. (Using hashes, you would be storing many many copies of the three strings'number','letter', and'word')