Here is how I understand your question:
if getline is called with qw(foo bar baz bletch) you want:
- foo bar to be OK,
- toto tutu to be NOT OK,
- foo bar toto to be NOT OK,
- foo foo to be OK,
- an empty input to be OK.
sub getline { return unless @_; # caller don't want + checks my %valid_word= map { ( $_, 1) } @_; # create a hash val +id_word => 1 my $line; chomp( $line = <>); my @word= split /\s/, $line; foreach my $word (@word) { return undef unless $valid_word{$word}; } # return failure as + soon as a a bad word is found return $line; }
Note that if you want to allow empty input lines you will have to test the result for undef, otherwise you can return 0 on failure or empty lines.
In reply to Re: Validating User Input
by mirod
in thread Validating User Input
by deprecated
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |