了解 Musicbrainz cpan 模块的输出类型?

发布于 2024-10-25 04:34:40 字数 485 浏览 1 评论 0原文

我使用 Musicbrainz cpan 模块来查找专辑,但在尝试破译我收到的输出时遇到了一些问题。我使用 data::Dumper 来查看它,它似乎是某种哈希或数组,但是当我尝试检查类型时遇到了问题。

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";
 }

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗地喜欢 2024-11-01 04:34:40

它是一个 WebService::MusicBrainz::Response 对象。

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";

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";
像你 2024-11-01 04:34:40

就像已经说过的,它是一个 WebService::MusicBrainz::Response 对象。
您可以通过访问 release_list() 来检索多个结果,它提供 WebService::MusicBrainz::Response::Release 对象。

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";
}

但是,该 perl 模块有些缺乏维护,并且它所使用的 XML Web 服务版本 1 已被弃用。

您最好使用 Web 服务的版本 2
python-musicbrainzngs 提供了一个使用新(下一代方案)Web 服务的 python 模块。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文