Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: How to print data between tags from file sequentially?

by AnomalousMonk (Archbishop)
on Jun 22, 2018 at 04:30 UTC ( [id://1217157]=note: print w/replies, xml ) Need Help??


in reply to How to print data between tags from file sequentially?

Quick and dirty:

c:\@Work\Perl\monks>perl -wMstrict -le "my @data = ( q{<Answer type='string'>ServerName</Answer>}, q{<Answer type='string'>10.10.10.11</Answer>}, q{<Answer type='string'>Windows Server 2012</Answer>}, ); ;; for my $datum (@data) { $datum =~ s{ \A .*? (?<= >) ([^<]*) .* }{$1}xms; print qq{'$datum'}; } " 'ServerName' '10.10.10.11' 'Windows Server 2012'
(Update: However, this solution is fragile; see Parsing HTML/XML with Regular Expressions (thanks to haukex).) The prepended labels I leave to you.

Update: The following works as well and may be preferable to a  s/// substitution as it is simpler:
    ($datum) = $datum =~ m{ (?<= >) [^<]* }xmsg;


Give a man a fish:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: How to print data between tags from file sequentially?
by TonyNY (Beadle) on Jun 22, 2018 at 16:56 UTC
    Thanks

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 08:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found