in reply to string containing characters

What have you tried? Maybe you should show us some sample code?

use strict; use warnings; my @wanted = (1, 2, 3, 4); for my $test ('1432', '1345', 'brown fox') { my $count = grep {$test =~ /$_/} @wanted; if ($count == @wanted) { print "'$test' contains all wanted characters\n"; } elsif ($count) { print "'$test' does not contain all wanted characters\n"; } else { print "'$test' contains no wanted characters\n"; } }

Prints:

'1432' contains all wanted characters '1345' does not contain all wanted characters 'brown fox' contains no wanted characters

Which contains some deliberate errors and should not be used for "production" code.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^2: string containing characters
by choroba (Cardinal) on Jan 21, 2025 at 09:32 UTC
    Or, without a regex:
    ... my $count = grep { -1 != index $test, $_ } @wanted; ...
    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^2: string containing characters
by ikegami (Patriarch) on Jan 21, 2025 at 22:42 UTC

    Note: Possibly ok, but doesn't handle duplicates in @wanted.

      Yes. The key deliberate

      should not be used for "production"
      issue. That might or might not be an issue for the OP, depending on how the test set of characters is generated. As always, with better information we can give better answers.

      Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond