Let\'s assume I have a shoping list stored as hash references: {122515=> { veggi
ID: 3581327 • Letter: L
Question
Let's assume I have a shoping list stored as hash references:
{122515=> {
veggie_diet => 'tofu',
meat_diet => 'lamb',
baby_diet => 'milk'}}
{122415=> {
veggie_diet => 'tempeh',
meat_diet => 'cod',
baby_diet => 'oats'}}
How would I turn these into refferences and how would I extract all of the data?
something like this?
{122515=> {
veggie_diet => 'tofu',
meat_diet => 'lamb',
baby_diet => 'milk'}}
{122415=> {
veggie_diet => 'tempeh',
meat_diet => 'cod',
baby_diet => 'oats'}}]
also, if I was to have my shopping list in the form of 2 arrays:
@diets = [veggie_diet , meat_diet , baby_diet ];
@foods=['tempeh', 'cod', 'oats'}
could I create and array of arrays based on the references? would I have to use a foreach to print the values?
Explanation / Answer
yes you can create arrays based on the references.
and yes we can use foreach on an array but no need of that long procedure. Because we have the corresponding element and item in same place of two arrays, we can loop it length times and print each value of array at i'th position
please comment below if any other doubt on the above code
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.