-1

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()";
TLP
  • 66,756
  • 10
  • 92
  • 149
JustCoder
  • 327
  • 1
  • 4
  • 13

1 Answers1

3

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.

TLP
  • 66,756
  • 10
  • 92
  • 149