in reply to Finding a partial match
G'day jpys,
This does what you asked for:
#!/usr/bin/env perl use strict; use warnings; my $string = '2cat6'; my @chars = split //, $string; my @tests = qw{2cat6 cat catch vwxyz 12345 67890 13457}; TEST: for my $test (@tests) { for my $char (@chars) { if (0 <= index $test, $char) { print "$test: true\n"; next TEST; } } print "$test: false\n"; }
Output:
2cat6: true cat: true catch: true vwxyz: false 12345: true 67890: true 13457: false
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Finding a partial match
by hv (Prior) on May 07, 2023 at 13:11 UTC | |
by kcott (Archbishop) on May 07, 2023 at 15:31 UTC |