in reply to checking array elements aginst another array

You cannot have more than one statement modifier, and you can't make up syntaxt :)
die "Unknown char! \n" unless exists $testHash{$_} for (@test);
is better written as
die "Unknown char! \n" unless grep { exists $testHash{$_} } @test;

Replies are listed 'Best First'.
Re^2: checking array elements aginst another array
by AnomalousMonk (Archbishop) on May 08, 2009 at 12:28 UTC
    ... better written as
       die "Unknown char! \n" unless grep { exists $testHash{$_} } @test;
    This will only  die when none of the characters in the test string are 'known':
    >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.
    A better way to write this (assuming something like Array::Diff is not acceptable) might be:
        exists $testHash{$_} or die "Unknown char! \n" for @test;