On 12/9/23 22:49, William Michels via perl6-users wrote:


On Dec 9, 2023, at 22:12, ToddAndMargo via perl6-users <perl6-us...@perl.org> wrote:

On 12/9/23 21:32, ToddAndMargo via perl6-users wrote:
On 12/9/23 19:42, William Michels via perl6-users wrote:

On 12/9/23 17:44, Tom Browder wrote:
> Try: say so $=....
>

Would you give me a quick example?

Hi Todd!

<SNIP>

HTH, Bill.
Awesome!  Thank you!
:-) :-) :-)


Hi Bill,

I was going to make a keeper out of your examples which explanations.
Not to ask too stupid a question, but what should I call teh keeper?

Many thanks,
-T


Hi Todd,

I should have annotated my examples. I'd just call these "match explorations". You'd probably want to write something like:

if $x.match( / ^ <+[0..9] + [a..z]> ** 7 $ / ) { do something...};

#Below: use <alnum> character class, which also includes underscores. Smartmatching with match return:
[0] > my $x="abc2def"; say  $x ~~ / ^ <alnum> ** 7 $ /;
「abc2def」
  alnum => 「a」
  alnum => 「b」
  alnum => 「c」
  alnum => 「2」
  alnum => 「d」
  alnum => 「e」
  alnum => 「f」

#Below: not a great example (waiting for a fellow Rakoon to chime in and explain):
[0] > my $x="abc2def"; .so.put if  $x ~~ / ^ <alnum> ** 7 $ /;
False

#Below: use `so`. Automatic return in the REPL. But are parentheses required?
[0] > my $x="abc2def";   $x ~~ / ^ <alnum> ** 7 $ /.so;
True

#Below: automatic return in the REPL. Parentheses work:
[1] > my $x="abc2def";   ($x ~~ / ^ <alnum> ** 7 $ /).so;
True

#Below: use `Bool` instead of `so`:
[2] > my $x="abc2def";   Bool($x ~~ / ^ <alnum> ** 7 $ /);
True

#Below: use `Bool` to check an 8-character match (should return `False`):
[3] > my $x="abc2def";   Bool($x ~~ / ^ <alnum> ** 8 $ /);
False

#Below: use `Bool`, back to a  7-character match, add `say`:
[4] > my $x="abc2def";   Bool($x ~~ / ^ <alnum> ** 7 $ /).say;
True

#Below: use `Bool`, a  8-character (non)-match, with `say`:
[4] > my $x="abc2def";   Bool($x ~~ / ^ <alnum> ** 8 $ /).say;
False

#Below: make a custom `<[0..9] + [a..z]>` character class and test for 7 (or 8) character match:
[4] > my $x="abc2def";   Bool($x ~~ / ^ <[0..9] + [a..z]> ** 7 $ /).say;
True
[4] > my $x="abc2def";   Bool($x ~~ / ^ <[0..9] + [a..z]> ** 8 $ /).say;
False

#Below, add a leading `+` to the custom character class, just to be careful:
[4] > my $x="abc2def";   Bool($x ~~ / ^ <+[0..9] + [a..z]> ** 8 $ /).say;
False

##Below, remove `Bool` and rearrange `so` to give final code:
[4] > my $x="abc2def";   say so $x.match: / ^ <+[0..9] + [a..z]> ** 8 $ /;
False
[4] > my $x="abc2def";   say so $x.match: / ^ <+[0..9] + [a..z]> ** 7 $ /;
True

HTH, Bill.

Awesome!

Reply via email to