in reply to Re^2: Print word from text file that is not an exact match
in thread Print word from text file that is not an exact match
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Print word from text file that is not an exact match
by TonyNY (Beadle) on Jun 10, 2018 at 18:40 UTC | |
by Laurent_R (Canon) on Jun 10, 2018 at 22:15 UTC | |
by TonyNY (Beadle) on Jun 12, 2018 at 01:45 UTC |