in reply to Regex checking text is made up of the keys of a hash.
Given the fixed hash %validLanguages (note that there is a level of hell for devising that name),
Start the sub definition and shift in one argument:
now split the string on combinations of a character class of comma and whitespace: my @langs = grep {defined} split /[\s,]+/, $text; look for nonexistent keys and return the negation of scalar of that list - gives zero if some were found, one if none were. End of sub.sub is_valid_list { my $text = shift;
That's untested but I figure it will work.! grep { ! exists $validLanguages{$_} } @langs; }
Update: The original failed for strings with [\s,]+ at the ends. Inserted grep {defined} to take care of that.
After Compline,
Zaxo
|
|---|