A. Pagaltzis wrote:
I have the following code:
class MyStupidString {
method repeatit(Str $string, Int $repeat) {
say $string xx $repeat;
my $add = $string xx $repeat;
say $add;
}
};
my $obj = MyStupidString.new;
$obj.repeatit("---",10);
Interestingly, it says:
> pugs test2.p6
------------------------------
--- --- --- --- --- --- --- --- --- ---
What am I misunderstanding here?
The `xx` operator. That's list-repeat, not string-repeat.
In Perl 5 terms, the code you wrote is:
sub repeatit {
my ( $string, $repeat ) = @_;
my @res = ( $string ) x $repeat;
print @res;
my $add = "@res";
print $add;
}
which should make it obvious what is going on.
Thank you and Juerd.
It was indeed a misunderstanding, I though "x" changed to "xx" in Perl6
for some reasons...
Now is the first time I write some Perl6 code that I actually run, too
:) It is *really* enjoyable. Feels like "this is how Perl should really
look like", and it is so DWIM I can hardly believe it. Kudos to all who
helped to make it happen!
- Fagzal