Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8519201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:11:04+00:00 2026-06-11T06:11:04+00:00

Lots of threads about iterating over an array of hashes, which I do daily.

  • 0

Lots of threads about iterating over an array of hashes, which I do daily. However now I want to iterate over an AoH in and AoH. I’m interested in the array “chapters” because I want to add a hash to each array element of that inner array:

$criteria = [
    {
      'title' => 'Focus on Learning',
      'chapters' => [
                          {
                            'content_id' => '182',
                            'criteria_id' => '1',
                            'title' => 'Focus on Learning',
                          },
                          {
                            'content_id' => '185',
                            'criteria_id' => '1',
                            'title' => 'Teachers Role',
                          },
                          {
                            'content_id' => '184',
                            'criteria_id' => '1',
                            'title' => 'Parents in Class',
                          },
                          {
                            'content_id' => '183',
                            'criteria_id' => '1',
                            'title' => 'Students at Home',
                          }
                        ],
      'tot_chaps' => '4'
    },

This, in theory, is want I want to do.

for my $i ( 0 .. $#$criteria ) {
   for my $j ( 0 .. $#$criteria->[$i]{'chapters'}) {
      print $criteria->[$i]{'chapters'}->[$j]{'title'}."\n";
   }
}

print $criteria->[$i]{'chapters'}->[1]{'title'}."\n"; -> Teachers Role
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:11:05+00:00Added an answer on June 11, 2026 at 6:11 am

    If you want to add something, just do it. I’m not sure I understood where you want to add what exactly. If you want another key/value pair for each of the chapters, do it like this:

    for my $i ( 0 .. $#$criteria ) {
      for my $j ( 0 .. $#{$criteria->[$i]{'chapters'}}) {
        $criteria->[$i]{'chapters'}->[$j]->{'Teachers Role'} = 'Stuff';
      }
    }
    

    Also, there was a little bug in the code: use $#{$criteria->[$i]{'chapters'}} instead of $#$criteria->[$i]{'chapters'} because the $# part only works until the first ->, so it tries to access ->[$i]{'chapters'} out of the value of $#$criteria which is a number and doesn’t work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen lots of threads about date ranges in MySQL but I still don't
Folks, I know there have been lots of threads about forcing the download dialog
I'm learning about threads in Java right now, along with all the concepts and
This is a very serious question: I've seen lots of threads here about gravatars
I've read lots of similar threads about the same issue but the fixes aren't
I've read through lots of threads on this, and followed the instructions at http://www.eventhelix.com/RealtimeMantra/HeaderFileIncludePatterns.htm
I have a python script that uses threads and makes lots of HTTP requests.
Lots of Installer questions, but I can't find the answer to what I want.
Lots of information on NSDates about the place, but I haven't found a clear
Firstly, I've never used threads, but have found lots of examples on the internet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.