in reply to Ask user to enter IP address repitatively for entities like Netmask, Gateway, DNS, bonds etc till correct address entered

Are you having trouble with the loop construct?

Perhaps something like this? (Completely untested)

my @bonds = qw(bond2 bond3 bond4 bond6 bond7 bond8); my %ipaddress_namei; while (my @bonds_with_invalid_ip = grep { not exists $ipaddress_namei{ +$_}, $_ }, @bonds) { for my $bond (@bonds_with_invalid_ip) { printf "Enter IP address of %s\n", ucfirst($bond); my $bond_in = <STDIN>; chomp($bond_in); if (is_ipv4($bond_in)) { $ipaddress_namei{$bond} = {$bond_in}; } } }

Update, a little simpler, using a FIFO:

my @bonds = qw(bond2 bond3 bond4 bond6 bond7 bond8); my %ipaddress_namei; # Use @bonds as a FIFO while (my $bond = shift @bonds) { printf "Enter IP address of %s\n", ucfirst($bond); my $bond_in = <STDIN>; chomp($bond_in); if (is_ipv4($bond_in)) { $ipaddress_namei{$bond} = {$bond_in}; } else { # try again next time around push @bonds, $bond; } }

-QM
--
Quantum Mechanics: The dreams stuff is made of

  • Comment on Re: Ask user to enter IP address repitatively for entities like Netmask, Gateway, DNS, bonds etc till correct address entered
  • Select or Download Code