in reply to Validating User Input
In any case, your code will accept or reject based only on the last element of @_. If the regex matches, $bool will be undef, and if the regex doesn't match, $bool will be true, regardless of how all the previous regexes turned out.
As soon as you know you want to accept/reject input, you should last out of the loop. For example:
sub getline { my $line = <>; chomp $line; if (@_) { my $reject; for (@_) { if ($line =~ /$_/) { $reject = 1; last; } } $line = undef if $reject; } return $line; }
|
|---|