Eugene Barsky:
I'm only beginning to study classes, so I don't understand the basics.
I want a method to construct regex
using attributes of the object:
class TEST {
has Str $.str;
method reg {
return
rx/
*
$!str
/;
}
}
my $var = TEST.new(str => 'baz');
say $var.reg;
When trying to run this program, I get the following Error message:
===SORRY!=== Error while compiling /home/evb/Desktop/p6/e.p6
Attribute $!str not available inside of a regex, since regexes are methods on Cursor.
Consider storing the attribute in a lexical, and using that in the regex.
at /home/evb/Desktop/p6/e.p6:11
------> ⏏
expecting any of:
infix stopper
So, what's the right way to do that?
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots