On Sat, Mar 25, 2017 at 1:15 AM, ToddAndMargo <toddandma...@zoho.com> wrote:
> Would this be the logical AND equivalent?
>
>     if $Terminal ~~ /xterm && linux/ {}

Nope! I tried it out.

-y
-y


On Sat, Mar 25, 2017 at 7:31 AM, yary <not....@gmail.com> wrote:
> On Sat, Mar 25, 2017 at 1:15 AM, ToddAndMargo <toddandma...@zoho.com> wrote:
>> On 03/24/2017 07:45 PM, Brad Gilbert wrote:
>>>
>>> All of these should work
>>>
>>>     if $Terminal ~~ /xterm/ | /linux/ {}
>>>     if $Terminal ~~ /xterm | linux/ {}
>>>     if $Terminal ~~ /xterm || linux/ {}
>>>
>>> Note that | in a regex tries both sides as if in parallel, and goes
>>> for the longest,
>>
>>
>> Hi Brad,
>>
>> What do you mean by longest?
>
>
> my $a = 'Bart sez cowabunga!';
>
> # matches cowabunga because that's the longest match
> $a ~~ / cow | cowabunga /;
> say $/;  # "cowabunga"
>
> # matches cow because it is the first alternation
> $a ~~ / cow || cowabunga /;
> say $/;  # "cow"
>
> This is useful in writing parsers- when given a choice of keywords
> that have the same prefix, longest match will find the keyword people
> expect regardless of the order of the alternations. Keeps people from
> having to remember to also search for a word boundary at the end,
> makes it easier to write bug-free grammars.
>
> -y

Reply via email to