Let me, however, continue with my earlier idea and show how split could be used in such a case. The following is a demonstration under the Perl debugger:
You could also retrieve directly the server name without using a temporary array:DB<1> $string = '<Answer type="string">ServerName.FD.net.org</Answer +>'; DB<2> @fields = split /[<>]/, $string; DB<3> x @fields; # displaying the content of the @fields array +after the split 0 '' 1 'Answer type="string"' 2 'ServerName.FD.net.org' 3 '/Answer' DB<4> print $fields[2]; # outputting the server name ServerName.FD.net.org
But, again, a regex capture is simpler with your data format.DB<1> $string = '<Answer type="string">ServerName.FD.net.org</Answer +>'; DB<2> $name = (split /[<>]/, $string)[2]; DB<3> print $name; ServerName.FD.net.org
In reply to Re^3: Print word from text file that is not an exact match
by Laurent_R
in thread Print word from text file that is not an exact match
by TonyNY
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |