if (($i =~ $vdbhosts[$i - 1])||($i == 0)){ #### # Get count of hosts found for the specified cluster my $chostcounter = 0; foreach my $chost (@$host_views) { $chostcounter++; } # Check that hosts exist, display error and re-direct to CLUSTER: if ($chostcounter == 0){ print "\n"; print BOLD WHITE ON_RED, "Error: No hosts were found in the " . $cluster_name . " cluster!\n", RESET; goto CLUSTER; } # Export cluster hosts list to a file my $chosts_file = '/root/deploypoc/export/cluster_hosts.txt'; open (CHOSTSFILE, '>', $chosts_file) or die " Problem opening $chosts_file\n"; foreach my $chost (@$host_views) { print CHOSTSFILE $chost->{'name'}, "\n"; } close CHOSTSFILE; # VDB host selection print BOLD WHITE ON_BLUE, " Host Selection: The following hosts were found for the \n" . " specified cluster. Please select the number(s)that \n" . " correspond to the desired host(s). If entering more than \n" . " one (1), separate each entry with a comma (1,2,3...) \n", RESET; print "\n"; # Import cluster hosts list and print sorted output use File::Slurp; my @chosts = read_file($chosts_file); my @vdbhosts = sort @chosts; CLUSTER_HOSTS: foreach my $i (0..$#vdbhosts ) { printf '%-2s',""; print $i + 1 . ". $vdbhosts[$i]"; } print "\n"; ASSIGN_VDB_HOSTS: # Select the hosts from the list above print "Enter selection(s): "; my $vdbhostinput = (<>); chomp $vdbhostinput; print "\n"; my @vdblist = split(',', $vdbhostinput); print "The following hosts were selected:\n\n"; foreach my $i (@vdblist){ # Check to ensure user input is valid and display selected hosts if (($i != $vdbhosts[$i - 1])||($i == 0)){ print BOLD WHITE ON_RED; print "Error: $i does not correspond to a host in the list!"; print RESET; print "\n\n"; goto CLUSTER_HOSTS; } print " " . $i . ". " . $vdbhosts[$i - 1]; }