Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: ... architecting & implementing help w/ Perl...

by rickkar (Initiate)
on Oct 25, 2012 at 18:04 UTC ( #1000913=note: print w/replies, xml ) Need Help??

in reply to Re: ... architecting & implementing help w/ Perl...
in thread ... architecting & implementing help w/ Perl...

something like this...?

use File::Find; my $client = REST::Client->new( $an_url ); File::Find::find( sub { return unless m/\.xml$/; carp "Could not open $File::Find::name!" unless open( my $fh, '<', $File::Find::name ) ; my $doi; while ( <$fh> ) { next unless ( $doi ) = m{[^/]*/([^/]*)}; $client->GET( join( '/', $base, $doi )); do_stuff_with_content( $client->responseContent ); } close $fh; } => '.' );

Replies are listed 'Best First'.
Re^3: ... architecting & implementing help w/ Perl...
by aitap (Deacon) on Oct 25, 2012 at 18:16 UTC

    Yes, looks correct.

    You may want to use some XML parser (XML::Twig, for example) to search for data in the XML files if you are not completely sure that internal representation of XML data will not change.

    You can also use File::Slurp and read files requiring less lines of code.

    Sorry if my advice was wrong.
Re^3: ... architecting & implementing help w/ Perl...
by rickkar (Initiate) on Oct 26, 2012 at 17:04 UTC

    i'm able to refine the problem...

    Statement of the Problem: parse Medline/Pubmed file paths on a Unix system in order to finally pass the PMID from each path to a pmid2doi conversion website < > ... and output companion DOIs…

    (1) parse this link and fetch the pmid; "/xxxxx/xxxxx/xxxxx/xxxxx/xxxxx/UNC00000000000042/00223468/v45i3/S0022346809003820";

    (2) submit a query to, fetch the return contents and parse the DOI value.

    If you simply point your browser to:

    then your browser will display the result in the form: {"pmid":18507872,"doi":"10.1186/gb-2008-9-5-r89"}

    and then you need to parse this JSON format.

    Examples of how to do that are at:

    #!/usr/local/bin/perl use strict; use warnings; use 5.010; use LWP::Simple; # Fetch line from <DATA> while ( <DATA> ) { # PMID is an 8-digit string, surrounded by "/" and "/" my $pmid = $1 if ( /\/(\d{8})\// ); # Query pmid in my $ret = get("$pmid"); unless (defined $ret) { warn "Failed to get doi for '$pmid': $!\n"; next; } # Parse query result, which would be like: # {"pmid":18507872,"doi":"10.1186/gb-2008-9-5-r89"} if ( $ret =~ /"doi":"(.*?)"}/ ) { my $doi = $1; # Output say $pmid, "\t=>\t", $doi; } else { say "doi not found in '$ret'"; } } exit 0; __DATA__ /xxxxx/xxxxx/xxxxx/xxxxx/xxxxx/UNC00000000000042/00223468/v45i3/S00223 +46809003820

    i'd appreciate any critiques/insights -- thx!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000913]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2016-10-27 01:29 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (351 votes). Check out past polls.