in reply to ensure ALL patterns in string

There are few ways you can condense this, here is one:

print "all in m8\n" if $var =~ /.*x.*y.*z.*/;
As in:
for (<DATA>) { chomp; print "$_: all in m8\n" if /.*x.*y.*z.*/; } __DATA__ foo xoo fyo foz xyo fyz xyz

UPDATE: Nope, that won't capture 'zyx' (and .* is awful) ... you could mangle the regex more or ... just use a lookup table:

my %hash = ( x => 1, y => 1, z => 1 ); for (<DATA>) { chomp; my $in = 0; my %hash = ( x => 1, y => 1, z => 1 ); for my $x (split //, $_) { delete $hash{$x} and $in++; } print "$_: all in m8\n" if $in == 3; }
That works, but perhaps List::Util is the way to go ... yes, i think so. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: ensure ALL patterns in string
by previous (Sexton) on Jan 22, 2016 at 21:47 UTC
    Thanks for the alternatives. I'm quite new to Perl and it's very educational to see the various methods. Thank you.