Im using the Musicbrainz cpan module to look up an album but Im having a few issues trying to decipher the output I recieve. I used data::Dumper to have a look at it, and it appears to be a hash or array of some sort but when I try to check the type I run into problems.
my $ws = WebService::MusicBrainz::Release->new();
my $response = $ws->search({ TITLE => 'ok computer' });
if (ref($response) eq "REF" || ref($response) eq "SCALAR" ||开发者_运维知识库 ref($response) eq "ARRAY" || ref($response) eq "HASH" || ref($response) eq "CODE" || ref($response) eq "GLOBE")
{
print "\n What sort of thing is it? \n";
}
Thanks
It's a WebService::MusicBrainz::Response object.
use WebService::MusicBrainz::Release;
my $ws = WebService::MusicBrainz::Release->new();
my $response = $ws->search({ TITLE => 'ok computer' });
my $release = $response->release(); # grab first one in the list
print $release->title(), " (", $release->type(), ") - ", $release->artist()->name(), "\n";
Like already said, it is a WebService::MusicBrainz::Response object. You can retrieve multiple results with accessing the release_list() which gives an array of WebService::MusicBrainz::Response::Release objects.
use WebService::MusicBrainz::Release;
my $ws = WebService::MusicBrainz::Release->new();
my $response = $ws->search({ TITLE => 'ok computer' });
my @releaselist = $response->release_list();
foreach my $release ( @releaselist ) {
print $release->title(), " - ", $release->artist()->name(), "\n";
}
However, that perl module is somewhat unmaintained and the XML Web service Version 1 it is using is deprecated.
You better use Version 2 of the Web Service. With python-musicbrainzngs there is a python module available that uses the new (next generation scheme) Web Service.
精彩评论