Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: .contains question

0 views
Skip to first unread message

Elizabeth Mattijsen

unread,
Dec 10, 2023, 6:30:06 PM12/10/23
to ToddAndMargo via perl6-users
my @letters = <a b 3>;
if $x.contains(any @letters) {
...


> On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users <perl6...@perl.org> 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

Elizabeth Mattijsen

unread,
Dec 11, 2023, 4:30:05 AM12/11/23
to ToddAndMargo via perl6-users
my $x="abc45def";
my @y=<a b c d e f g h i j 1 2 3 4 5>; say so $x.contains(any @y);

"so" will collapse the junction into a Bool.
"say" will append a \n for you, so you don't have to.

> On 11 Dec 2023, at 01:52, ToddAndMargo via perl6-users <perl6...@perl.org> wrote:
>
>>> On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users <perl6...@perl.org> 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
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>

0 new messages