in reply to How to print data between tags from file sequentially?
Quick and dirty:
(Update: However, this solution is fragile; see Parsing HTML/XML with Regular Expressions (thanks to haukex).) The prepended labels I leave to you.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: 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 |