use strict; use warnings; use open qw<:std :encoding(UTF-8) >; use Data::Dumper; use REST::Client::CrossRef; use Log::Any::Adapter( 'File', './log_auth.txt', "log_level" => "info" ); use JSON::Path; my $cr = REST::Client::CrossRef->new( mailto => 'd...h', spit_raw_data => 0, add_end_flag => 1, json_path => [ ['$.title'], ['$.author'], ], json_path_callback => { '$.author' => \&unfoldauthors }, ); $cr->init_cache( { BasePath => "C:\\Windows\\Temp\\perl", NoUpdate => 15 * 60, verbose => 0 } ); sub unfoldauthors { my ($data_ar) = @_; return unless ($data_ar); $data_ar = $data_ar->[0]; my @paths = qw( $..family $..given $..affiliation ); my @selectors; for my $p (@paths) { push @selectors, JSON::Path->new($p); } my $aff_name = JSON::Path->new('$..name'); my $name; my @lines; my @sep = ( ", ", "; ", " " ); my $col = 0; for my $s (@selectors) { my @text = $s->values($data_ar); my $authors_limit = 50; my $last = $authors_limit - 1; if ( @text > $authors_limit ) { @text = @text[ 0 .. $last ]; $text[$last] .= " ..." if ( $col == 1 ); } my $pos = 0; for my $name (@text) { print "$col $name\n"; if ( $col == 2 ) { my @aff = $aff_name->values( $text[$pos] ); $name = join( " - ", @aff ); } $lines[ $pos++ ] .= $name . $sep[$col]; } $col++; } return \@lines; } $cr->init_cache( { BasePath => "C:\\Windows\\Temp\\perl", NoUpdate => 15 * 60, verbose => 0 } ); my $select = "author,title"; while () { chomp; my $data = $cr->works_from_doi( $_, { 'has-affiliation' => 'true' }, $select ); next unless ($data); for my $row (@$data) { print "\n" unless ($row); while ( my ( $f, $v ) = each %$row ) { if ( $f eq '$.title' ) { print "***$v\n\n"; } else { print "$v \n"; } } } } __DATA__ 10.1111/jph.12775