I have a parsing environment (Marpa::R2::Scanless) that needs to use single Perl regexp character classes to control tokenizing. I've got something to tokenize that doesn't seem to fit any of the existing character classes. So, after digging around in the perlunicode docs, I've come up with the following code, except it doesn't work as expected. I expect to see a row of dots interspersed with all the non-alphanumerics (except parens). Instead, I get a runtime error about not being able to find the character class.
#!/usr/bin/env perl
use 5.018;
use utf8;
local $| = 1;
for my $i (map { chr($_) } 32 .. 127) {
if ($i =~ /\p{Magic::Wow}/) {
print $i;
}
else {
print ".";
}
}
package Magic;
sub Wow {
return <<'MAGIC';
+utf8::Assigned
-utf8::Letter
-utf8::Number
-0028
-0029
MAGIC
}
1;
Any hints, tips, tricks, or suggestions?
Name the sub IsWow
and the property Magic::IsWow
.
Quoting User-Defined Character Properties in perlunicode:
You can define your own binary character properties by defining subroutines whose names begin with "In" or "Is".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With