Oops— I sent the following yesterday and it somehow didn't go to the list:

On Mon, Sep 10, 2018 at 19:02 ToddAndMargo <toddandma...@zoho.com> wrote:

> Question, what the heck is
>
>       my $rx1 = rx:i/a/;
>
> Are they talking over beginner's heads again?
>

In the sense of "beginners to Perl", perhaps, since "rx" is familiar to
Perl 5 programmers.

Though if you search docs.perl6.org for "rx" you'll see a choice in the
pop-down, "rx (quote)", which leads to:
https://docs.perl6.org/language/regexes#index-entry-quote_%2F_%2F-quote_rx-quote_m-Lexical_conventions
and
that says:

```

Perl 6 has special syntax for writing regexes:

    m/abc/;         # a regex that is immediately matched against $_

    rx/abc/;        # a Regex object; allow adverbs to be used before regex

    /abc/;          # a Regex object; shorthand version of 'rx/ /' operator
```

That entire section of the documentation is worth reading as it describes
everything discussed in this thread.

But in case it isn't clear, it just means that if you do

    my $result = "Juli 2018" ~~ m:i/jul/;

then you'll get a match containing "Jul" as a result.

It so happens in this case, when using ~~ against a literal like above, m//
and rx// are pretty much interchangeable.

But you could also do:

    my $pattern = rx:i/jul/;
    my $result = "Juli 2018" ~~ $pattern;

and get the same result.

If you tried to do

   my $pattern = m:i/jul/;

You'll get an exception unless the $_ topic variable happens to contain a
thing that can be regex-matched (like a string). The `m` explicitly causes
the match to happen immediately.

Reply via email to