in reply to IP address validation when IP is picked dynamically

Tip #3 from the Basic debugging checklist: chomp:

while (my $line =<$fh>) { chomp $line; next if $. < 2; my($key, $parameter_value) = split("=", $line);

Replies are listed 'Best First'.
Re^2: IP address validation when IP is picked dynamically
by rahulruns (Scribe) on May 01, 2015 at 12:36 UTC

    chomp does not have much effect. Still issue remains

    [root@localhost bond]# perl ifcfgbondverification.pl Enter the absolute directory location for ifcfg files /root/office/ifcfgverification/bond FailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFa +ilFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFai +lFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFailFail +FailFailFailFailFailFailFailFailFailFailFail[root@localhost bond]#
      chomp is needed (if the IP address is the last text on the line after the split), but it may not be a complete solution to your problem. Consider the following code:
      use warnings; use strict; use Data::Validate::IP qw(is_ipv4); while (my $line = <DATA>) { chomp $line; my($key, $parameter_value) = split("=", $line); if (is_ipv4($parameter_value)) { print $parameter_value; } else { print "Fail" } } print "\n"; __DATA__ abc=1.2.3.4

      It prints "1.2.3.4". If you comment out the chomp line, it prints "Fail".

      Maybe $parameter_value isn't what you think it is. Tip #2 from the Basic debugging checklist: print

      my($key, $parameter_value) = split("=", $line); print ">>>$parameter_value<<<\n";

      Could you try the code which I posted? post us the result of the script.


      All is well. I learn by answering your questions...