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