When I print the result of the regex I am attempting to use to control the until loop it gives me the 1 or null I am expecting. Why is it that the code below won't work but if I uncomment the fifth line it works fine?
print("Please enter 1, 2, 3 or 4 : ");
my $channelSelection = "";
until ($channelSelection =~ /^[1-4]$/) {
chomp(my $channelSelection = <STDIN>);
#last if ($channelSelection =~ /^[1-4]$/);
print ("Invalid choice ($channelSelection) please try again: ")
if ($channelSelection !~ /[1-4]/);
}
I'm sure this has been solved elsewhere but was unable to find it with search. Pointing me in the right direction would be great.
I would normally do something like.
print("Please enter 1, 2, 3 or 4 : ");
my $channelSelection = "";
while (1) {
chomp(my $channelSelection = <STDIN>);
last if ($channelSelection =~ /^[1-4]$/);
print ("Invalid choice ($channelSelection) please try again: ") if ($channelSelection !~ /[1-4]/);
}
But I'm trying to get away from the infinite loops.