3

私は Net::Twitter を使って Twitter メッセージにアクセスしています。現在、direct_message() はメッセージの配列を返します。私が見つけたのは、それが実際には配列の配列であることです(アカウントに基づいて、個々のメッセージに基づいています)。

結果からメッセージIDを出力するより良い方法を誰かが知っているかどうか知りたいですか? $msgs[0][0]{'id'} はメッセージIDを出力するため、配列の配列であるとしか考えていませんでした。データダンパーを実行すると、ハッシュの配列のように見えました。

foreach my $msg (@{$msgs[0]})
{
    print $msg->{'id'} . "\n";
}

データ::ダンパーの結果

$VAR1 = [
      {
        'sender_screen_name' => 'text',
        'recipient' => {
                         'friends_count' => 'text',
                         'follow_request_sent' => 'text',
                         'profile_background_image_url_https' => 'text',
                         'profile_sidebar_fill_color' => 'text',
                         'profile_image_url' => 'text',
                         'profile_background_color' => 'text',
                         'notifications' => 'text',
                         'url' => 'text',
                         'id' => 'text',
                         'is_translator' => 'text',
                         'following' => 'text',
                         'screen_name' => 'text',
                         'lang' => 'text',
                         'location' => 'text',
                         'followers_count' => 'text',
                         'statuses_count' => 'text',
                         'name' => 'text',
                         'description' => 'text',
                         'favourites_count' => 'text',
                         'profile_background_tile' => 'text',
                         'listed_count' => 'text',
                         'contributors_enabled' => 'text',
                         'profile_link_color' => 'text',
                         'profile_image_url_https' => 'text',
                         'profile_sidebar_border_color' => 'text',
                         'created_at' => 'text',
                         'utc_offset' => 'text',
                         'verified' => 'text',
                         'show_all_inline_media' => 'text',
                         'profile_background_image_url' => 'text',
                         'protected' => 'text',
                         'default_profile' => 'text',
                         'id_str' => 'text',
                         'profile_text_color' => 'text',
                         'default_profile_image' => 'text',
                         'time_zone' => 'text',
                         'profile_use_background_image' => 'text',
                         'geo_enabled' => 'text',
                       },
        'id_str' => 'text',
        'sender_id' => 'text',
        'created_at' => 'text',
        'text' => 'text',
        'sender' => {
                      'friends_count' => 'text',
                      'follow_request_sent' => 'text',
                      'profile_background_image_url_https' => 'text',
                      'profile_sidebar_fill_color' => 'text',
                      'profile_image_url' => 'text',
                      'profile_background_color' => 'text',
                      'notifications' => 'text',
                      'url' => 'text',
                      'id' => 'text',
                      'is_translator' => 'text',
                      'following' => 'text',
                      'screen_name' => 'text',
                      'lang' => 'text',
                      'location' => 'text',
                      'followers_count' => 'text',
                      'statuses_count' => 'text',
                      'name' => 'text',
                      'description' => 'text',
                      'favourites_count' => 'text',
                      'profile_background_tile' => 'text',
                      'listed_count' => 'text',
                      'contributors_enabled' => 'text',
                      'profile_banner_url' => 'text',
                      'profile_link_color' => 'text',
                      'profile_image_url_https' => 'text',
                      'profile_sidebar_border_color' => 'text',
                      'created_at' => 'text',
                      'utc_offset' => 'text',
                      'verified' => 'text',
                      'show_all_inline_media' => 'text',
                      'profile_background_image_url' => 'text',
                      'protected' => 'text',
                      'default_profile' => 'text',
                      'id_str' => 'text',
                      'profile_text_color' => 'text',
                      'default_profile_image' => 'text',
                      'time_zone' => 'text',
                      'profile_use_background_image' => 'text',
                      'geo_enabled' => 'text',
                    },
        'recipient_screen_name' => 'text',
        'id' => 'text',
        'recipient_id' => 'text',
      }
    ];
4

1 に答える 1

2

私が見たところNet::Twitter、それは本質的に非常に骨格的です。それはあなたを API に戻しますが、ほとんどそのままにしておきます。主な理由は、API が絶えず変化しているため、安定したモジュールを作成するのが難しくなっているからです。ほとんどのモジュールは、配列のハッシュへのハッシュ参照の配列への参照への参照をクリーンアップしようとしますが、これはそうではありません。

Data::Dumperどのデータ構造が返されているかを確認し、できる限り最善の方法で解析する必要があるようです。

このような状況では、refコマンドを使用して、見ているものを正確に確認できます (配列への参照を期待しているときにハッシュへの参照が返される場合は、その方法で問題が発生する可能性があることがわかります)。Net::Twitter::Liteまた、基本的なオブジェクト処理をもう少しサポートする可能性があるものを確認することもできます。

于 2012-07-24T03:04:26.623 に答える