-1
#!/usr/bin/perl -w

use WWW::LinkedIn;
use CGI;    # load CGI routines
use CGI::Session;
$q = CGI->new;                      # create new CGI object
print $q->header,                   # create the HTTP header
  $q->start_html('hello world'),    # start the HTML
  $q->h1('hello world'),            # level 1 header
  $q->end_html;                     # end the HTML
my $consumer_key    = 'xxxxxxx';
my $consumer_secret = 'xxxxxxxxx';
my $li              = WWW::LinkedIn->new(
    consumer_key    => $consumer_key,
    consumer_secret => $consumer_secret,
);

if ( length( $ENV{'QUERY_STRING'} ) > 0 ) { 
    $buffer = $ENV{'QUERY_STRING'};
    @pairs = split( /&/, $buffer );

    foreach $pair (@pairs) {
        ( $name, $value ) = split( /=/, $pair );
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
        $in{$name} = $value;
    }   
    $sid = $q->cookie('CGISESSID') || $q->param('CGISESSID') || undef;

    $session = new CGI::Session( undef, $sid, { Directory => '/tmp' } );

    my $access_token = $li->get_access_token(
        verifier             => $in{'oauth_verifier'},
        request_token        => $session->param("request_token"),
        request_token_secret => $session->param("request_token_secret"),
    );  
    undef($session);
    my $profile_xml = $li->request(
        request_url =>
'http://api.linkedin.com/v1/people/~:(id,first-name,last-name,positions,industry,distance)',
        access_token        => $access_token->{token},
        access_token_secret => $access_token->{secret},
    );  
    print $profile_xml;
}

出力は 1 行で印刷されます。別行で印刷したい。

出力

aAVGFD34 jj DD 456456 2003 6 true ara systems Technology and Services  Technology and Services 0 

profile_xml 変数から各列の値を取得するにはどうすればよいですか?

id avsdff
first name jj
lastname dd
4

3 に答える 3

0

ハッシュ参照から簡単に出力してみてください

 foreach $key (keys %{$profile_xml}) {
     print "$key $profile_xml->{$key}\n";
 }
于 2013-09-07T18:51:12.330 に答える