#!/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)); closedir OPHOME; foreach(@files){ if (m/(op|nm)\d{2}$/) { push(@instances, $_); } } my $length = scalar(@instances); while ($j != 1) { &chooser( \@instances ); } open CHOSENENV, ">chosen_setup_env"; print CHOSENENV "$instances[$selection]"; close CHOSENENV; sub chooser { $i = 1; my ($arrayRef) = @_; print "\nAvailable Instances\n===================\n"; foreach(@$arrayRef) { print " $i. ",$_,"\n"; $i++; } print "\nSelect an instance and press enter: "; $selection = <>; chomp($selection); $selection -= 1; if ($selection < -1) { #!~ m/[1-$length]/) { print "\nIncorrect selection. Try again.\n"; } elsif ($selection > $length) { # !~ m/(\d{1})?/) { print "\nIncorrect selection. Try again.\n"; } else { $j = 1; } }
In reply to Re: Regex not working?
by peschkaj
in thread Regex not working?
by peschkaj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |