Re: .contains question

[email protected] (ToddAndMargo via perl6-users)
Newsgroups perl.perl6.users
Message-ID <[email protected]>
>> On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users <[email protected]> wrote:
>>
>> Hi All,
>>
>> my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" )  { print "True\n"; } else { print "False\n" };
>> True
>>
>> Is there a way to tell .contains that you want to know
>> if any of a sequence characters is in a string other that
>> repeating || over and over.  Any [a..z] or [0..9] option?
>>
>> Many thanks,
>> -T
> 

On 12/10/23 15:24, Elizabeth Mattijsen wrote:
 > my @letters = <a b 3>;
 > if $x.contains(any @letters) {


Hi Elizabeth,

Very interesting.  Problem: I was looking for one answer, not many

 > my $x="abc45def";my @y=<a b c d e f g h i j 1 2 3 4 5>; print 
$x.contains(any @y) ~ "\n";
True
True
True
True
True
True
False
False
False
False
False
False
False
True
True


Many thanks,
-T

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.