Okay, not sure where to ask this, but I’m a beginner programmer, using Perl. I need to create an array of an array, but I’m not sure if it would be better use array/hash references, or array of hashes or hash of arrays etc.
I need an array of matches: @totalmatches
Each match contains 6 elements(strings):
@matches = ($chapternumber, $sentencenumber, $sentence, $grammar_relation, $argument1, $argument2)
I need to push each of these elements into the @matches array/hash/reference, and then push that array/hash/reference into the @totalmatches array.
The matches are found based on searching a file and selecting the strings based on meeting the criteria.
QUESTIONS
-
Which data structure would you use?
-
Can you push an array into another array, as you would push an element into an array? Is this an efficient method?
-
Can you push all 6 elements simultaneously, or have to do 6 separate pushes?
-
When working with 2-D, to loop through would you use:
foreach (@totalmatches) {
foreach (@matches) {
…
}
}
Thanks for any advice.
Do not push one array into another array.
Lists just join with each other into a new list.
Use list of references.