Yeah you missed the chomp() in while loop as mentioned by toolic.More over did little bit changes in the script.
#!/usr/bin/perl use strict; use warnings; use Data::Validate::IP qw(is_ipv4); print "Enter the absolute directory location for ifcfg files\n"; my $directory = <>; chomp($directory); opendir(DIR, $directory) or die "couldn't open $directory: $!\n"; my @ifcfg_files = grep { /^ifcfg-bond/ } readdir(DIR); closedir DIR; foreach (@ifcfg_files) { my %hash = (); my $file = "$_"; open (my $fh, "<", $file) or die "Can't open the file $file: "; while (my $line =<$fh>) { chomp($line); next if $. <= 2; # Added '=' my($key, $parameter_value) = split("=", $line); next if $key eq "BONDING_OPTS"; if (is_ipv4($parameter_value)) { print "Success -> $key:$parameter_value\n"; } else{ print "Failed -> $key:$parameter_value\n" } } } #Outer Foreach
In reply to Re: IP address validation when IP is picked dynamically
by vinoth.ree
in thread IP address validation when IP is picked dynamically
by rahulruns
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |