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

  • Home
  • SEARCH
  • 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 4241082
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:15:20+00:00 2026-05-21T03:15:20+00:00

I am attempting to parse over the MediaWiki’s API output with format=yaml . My

  • 0

I am attempting to parse over the MediaWiki’s API output with format=yaml. My YAML code looks something like:

use YAML qw(Dump Bless Load);
use YAML::LoadURI;
use YAML::Tag;
my $yaml_hash = LoadURI($wiki_url);
my $id = $yaml_hash->{query}->{namespaces}->[0];
print $id;

This is fine and dandy, but how do you to iterate over the YAML output without brute forcing it? This would be idea, but obviously this does not work.

my $id = $yaml_hash->{query}->{namespaces}-[*]->{id}

This is what the YAML output looks like:

---
query:
  namespaces:
    -
      id: -2
      case: first-letter
      '*': Media
      canonical: Media
    -
      id: -1
      case: first-letter
      '*': Special
      canonical: Special
    -
      id: 0
      case: first-letter
      '*':
          content:
    -
      id: 1
      case: first-letter
      '*': Talk
      subpages:
      canonical: Talk
    -
      id: 2
      case: first-letter
      '*': User
      subpages:
      canonical: User
    -
      id: 3
      case: first-letter
      '*': User talk
      subpages:
      canonical: User talk
  • 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-05-21T03:15:21+00:00Added an answer on May 21, 2026 at 3:15 am

    Is this what you want? Note: I haven’t tested it:

    Goal: something "Like" $yaml_hash->{query}->{namespaces}-[*]->{id} — except functional

    Try this:

    my @ids = map { $_->{id} } @{$yaml_hash->{query}->{namespaces}} ;
    

    However, a for loop is probably clearer to a lot of people.

    my @ids;
    foreach my $ns ( @{$yaml_hash->{query}->{namespaces}} ){ push @ids, $ns->{id} }
    

    Note I am proceeding on general perl data structure knowledge, not anything YAML specific.

    It is assumed that ‘query‘ and ‘namespaces‘ are literals; if those are parameters then you need to brute force those with additional for-in or while loops. For iterating over hashes, look up keys() and each() in perldoc perlfunc.

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

Sidebar

Related Questions

I'm attempting to parse HTML code with DOMDocument, do stuff like changes to it,
So I'm attempting to use a queue to parse some input, turning prefix mathematical
I'm attempting to parse a JSON feed using the LastFM API but there are
I'm attempting to parse XML in the following format (from the European Central Bank
I am attempting to use BeautifulSoup to parse through a DOM tree and extract
I am attempting to parse a string in Perl with the format: Messages pushed
I am attempting to parse an output file for some data, and am having
I am attempting to use the Agility pack to parse certain bits of info
I am attempting to parse a string like the following using a .NET regular
I have a collection of documents that I'm attempting to parse. Like HTML, they

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.