> 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.
--
GMX DSL-Flatrate 0,- Euro* - Überall, wo DSL verfügbar ist!
NEU: Jetzt bis zu 16.000 kBit/s! http://www.gmx.net/de/go/dsl