in reply to checking array elements aginst another array
You could use grep instead of a loop to filter the characters.
use strict; use warnings; my %allowed = map { $_ => 1 } q{a} .. q{o}; my @testStrs = qw{ acbbedfydaccdtg abcde }; my @unknown = (); foreach my $testStr ( @testStrs ) { @unknown = grep { ! $allowed{ $_ } } split m{}, $testStr; print qq{String - $testStr: }, @unknown ? qq{Unknown characters found: @unknown\n} : qq{Success\n}; }
The output.
String - acbbedfydaccdtg: Unknown characters found: y t String - abcde: Success
I hope this is of use.
Cheers,
JohnGG
|
|---|