On Sun, 2005-12-04 at 13:10 -0500, Mike Li wrote: > what is a good translation of the following C into perl6? > <code> [...] > int x = 0; int y[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; y[x++]++; /* line > that matters */ [...] > </code> > > in perl5, i would've written something like: > <code> > my $x = 0; my @y = 1..9; @y[$x++]++; print "$x\n"; print "@y\n" > </code>
Note that when you run this in perl 5: $ perl -we 'my $x = 0; my @y = 1..9; @y[$x++]++; print "$x\n"; print "@y\n"' Scalar value @y[$x++] better written as $y[$x++] at -e line 1. 1 2 2 3 4 5 6 7 8 9 You've already used a Perl6-ism! > but in perl6, the '@' sigil always means list context, so should i > write the following? > > <code> > my $x = 0; my @y = 1..9; [EMAIL PROTECTED]; print "$x\n"; print "@y\n" > </code> I'm not sure what you're trying to do with all those derefs, but the only change you need to make to your original code is to put the @y interpolation inside a block; { my $x = 0; my @y = 1..9; @y[$x++]++; print "$x\n"; print "{ @y }\n" } Try downloading and installing pugs; it's great for trying out this sort of thing! Sam.