Regex example produces "Use of Nil in string context" exception.
daph opened this issue · comments
David Phillips commented
Going through the regex section, I follow along with the example, however, upon running the example I get
Use of Nil in string context
in block <unit> at e.pl6 line 5
is a valid email
I get his is with code copied straight out of the the book:
[ daph@archbox ~/perl6]% cat e.pl6
my $email = 'john.doe@perl6.org';
my $regex = / <:L>+\.<:L>+\@<:L+:N>+\.<:L>+ /;
if $email ~~ $regex {
say $/ ~ " is a valid email";
} else {
say "This is not a valid email";
}
My perl6 is rakudo-star 2016.10
Itsuki Toyota commented
@daph
Rakudo-star 2016.10 has a bug related to regex.
When you smartmatch against a regex stored variable, it returns Bool and doesn't generate a Match instance:
- 2016.10
$ perl6 -e 'my $a = rx/a/; ("a" ~~ $a).say; say $/;'
True
Nil
- latest version( Rakudo version 2016.10-295-g85c7072 )
$ perl6 -e 'my $a = rx/a/; ("a" ~~ $a).say; say $/;'
「a」
「a」
The above bug was already fixed and tested here:
Raku/roast@839566c
So, could you install the latest Rakudo with rakudobrew and try it again ?
David Phillips commented
Yup. It works with the latest rakudo. Thanks for the help.