#!/opt/perl5/bin/perl -w use strict; my @instances; my $i; my $selection = 0; my $j = 0; opendir OPHOME, "/opt/lnpsite" or die "Can't open /opt/lnpsite: $!\n"; my @files = sort(readdir(OPHOME)); foreach(@files){ if (m/(op|nm)\d{2}$/) { push(@instances, $_); } } my $length = scalar(@instances); while ($j != 1) { &chooser(); } $selection = $selection - 1; ## COMPLETELY UNNECESSARY DEBUGGING CODE ## ########################################### print "\nSELECTION IS: ",int($selection),".... LENGTH IS: $length\n"; print "j is: $j\n"; my $conn = "/opt/lnpsite/" . $instances[$selection] . "/scripts/setup_env"; symlink("$conn", ".setup_env"); open CHOSENENV, ">chosen_setup_env"; print CHOSENENV "$instances[$selection]"; close CHOSENENV; sub chooser() { $i = 1; print "\nAvailable Instances\n===================\n"; foreach(@instances) { print " $i. ",$_,"\n"; $i++; } print "\nSelect an instance and press enter: "; $selection = <>; chomp($selection); if ($selection !~ /[1-$length]/) { print "\nIncorrect selection. Try again.\n"; } elsif ($selection !~ m/\d?/) { print "\nIncorrect selection. Try again.\n"; } else { $j = 1; } }