in reply to Re: checking array elements aginst another array
in thread checking array elements aginst another array
... better written asThis will only die when none of the characters in the test string are 'known':
die "Unknown char! \n" unless grep { exists $testHash{$_} } @test;
A better way to write this (assuming something like Array::Diff is not acceptable) might be:>perl -wMstrict -le "my %testHash = map { $_ => 1 } 'a' .. 'j'; for my $str (@ARGV) { my @test = split '', $str; die qq{unknown char in '$str'} unless grep { exists $testHash{$_} } @test; print qq{'$str' ok}; } " abcd axyz xyz 'abcd' ok 'axyz' ok unknown char in 'xyz' at -e line 1.
|
|---|