in reply to ensure ALL patterns in string
There are few ways you can condense this, here is one:
As in:print "all in m8\n" if $var =~ /.*x.*y.*z.*/;
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:
That works, but perhaps List::Util is the way to go ... yes, i think so. :)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; }
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 |