开发者

How to write a single parsed line into paragraph?

开发者 https://www.devze.com 2023-03-22 17:23 出处:网络
I extracted a paragraph using XML::Simple parser. I got it parsed in a single line. Here is the code and I extracted abstract.

I extracted a paragraph using XML::Simple parser. I got it parsed in a single line. Here is the code and I extracted abstract.

use LWP::Simple;
use XML::Simple;
use Data::Dumper;

open (FH, ">:utf8","xmlparsed2.txt");
my $db1 = "pubmed";
my $q = 16404398;
my $xml = new XML::Simple;
$urlxml = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=$db1&id=$q&retmode=xml&rettype=abstract";
$dataxml = get($urlxml);
$data = $xml->XMLin("$dataxml", ForceArray => [qw( MeshHeading Author AbstractText )], ForceContent=>1);
print FH Dumper开发者_开发知识库($data);
print FH "Abstract: ".join "\n", map {join ":",($_->{NlmCategory},$_->{content})} @{$data->{PubmedArticle}->{MedlineCitation}->{Article}->{Abstract}->{AbstractText}};

My question is: can it be parsed to fit the window and be in a paragraph rather than in a single line?


My question is can it be parsed to fit the window

So question 1, how to determine the size of terminal window

The answer is use

use Term::Size;

($columns, $rows) = Term::Size::chars *STDOUT{IO};
($x, $y) = Term::Size::pixels;

and be in paragraph rather than in a single line?

for question 2, use core module Text::Wrap, or Text::Fold ...

0

精彩评论

暂无评论...
验证码 换一张
取 消