in reply to [Perl6] say variable in Class
Your code is almost valid Perl 6. In order to inspect attribute $!x you have to construct an object instance leading to the two suggestions below. See the Perl 6 Object Orientation document for more.
The first approach is a more usual starting point for development.
class A { has Str $.x ; method test { say 'Test'; say $!x ; } } A.new(x =>'hello').test;
The second approach is more advanced but may be closer to the OP intentions.
class A { has Str $.x ; submethod TWEAK { say 'Test'; say $!x ; } } A.new;
Ron
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: say variable in Class
by Edelbaer (Initiate) on Jun 02, 2018 at 18:12 UTC | |
by Laurent_R (Canon) on Jun 03, 2018 at 16:32 UTC |
In Section
Seekers of Perl Wisdom