How to take IP address as input

245 Views Asked by At

How to take IP address as input and use it in the Xpath expressions? When i am using it as a static input like $iptext = '10.109.25.1'; it is working fine but when i am getting the input from user i am getting error

#my $ip = <>;
#my $iptext=$ip.'';
my $query  = "//nodeA/nodeB[nodeC/text() = '$iptext']/../NodeD/Name/text()";
1

There are 1 best solutions below

0
On BEST ANSWER

I assume what you are forgetting is that input read with <> or <STDIN> come with newlines:

chomp(my $ip = <>);   # newline removed

Documentation for chomp here.

If you do not remove the newline, your $query string will contain that newline, which I assume you pass to Xpath or some such:

xpath //nodeA/nodeB[nodeC/text() = '10.109.25.1
']/../NodeD/Name/text()

And of course that does not work.