in reply to Check Array Elements

Look Ma ! - No temp hash! (Good if you are doing this check only a small number of times).
if ((my $x=grep {/ABC|GHI|MNO/}@FILES) == 3){ print qq|Found them all\n| }else{ print qq|found only $x\n| }
Update Ignore the buggy version above. Revised, based on morgons (++) observations below ..
my @need=sort qw|ABC GHI MNO|; my $flat=join "",@need; my $re="\\b" . join( "|",@need)."\\b"; if ($flat eq join( "", sort grep{m/$re/}@FILES)){ say "Found!" }

             I hope life isn't a big joke, because I don't get it.
                   -SNL

Replies are listed 'Best First'.
Re^2: Check Array Elements
by morgon (Priest) on Jun 06, 2012 at 22:41 UTC
    This is wrong.

    Counterexample:

    @FILES = ("ABC", "ABC", "ABC");
    Your grep would still report 3, event though "GHI" is missing.

    And that is even without mentioning that the regex matches also enties like "XABCY".

      Thanks for pointing out the bugs (++). Code updated above.

      I think that method is getting unwieldy. Much prefer ckjs approach below.

                   I hope life isn't a big joke, because I don't get it.
                         -SNL

        serious ++. I love seeing this type of accountability. I know I often have to swallow it.