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: <%-{-{-{-<
In reply to Re: How to print data between tags from file sequentially?
by AnomalousMonk
in thread How to print data between tags from file sequentially?
by TonyNY
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |