Not even a reset- every time there's a $ by itself it is a new/different anonymous variable. So it is only useful where it is never referred to anywhere else.
$ raku -e "for (1..4) { say $++, ' , ', ++$; say 'again- ',$;}" 0 , 1 again- (Any) 1 , 2 again- (Any) 2 , 3 again- (Any) 3 , 4 again- (Any) Hmm, how to make an alpha counter? $ raku -e "for (1..4) { say ($ ||= 'AAA')++ }" AAA AAB AAC AAD There is also anonymous @ and % but I don't have an example off the top of my head. -y On Mon, Aug 31, 2020 at 4:57 PM ToddAndMargo via perl6-users < perl6-us...@perl.org> wrote: > On 2020-08-31 16:53, ToddAndMargo via perl6-users wrote: > >>> On Mon, Aug 31, 2020, 4:20 PM ToddAndMargo via perl6-users > >>> <perl6-us...@perl.org <mailto:perl6-us...@perl.org>> wrote: > >>> > >>> On 2020-08-31 05:53, Brian Duggan wrote: > >>> > On Monday, August 24, Curt Tilmes wrote: > >>> >> $ cat Lines.txt | raku -e '.say for lines()[3,2,5]' > >>> > > >>> > The -n flag is an option here too: > >>> > > >>> > raku -ne '.say if $++ == 3|2|5' Lines.txt > >>> > > >>> > Brian > >>> > > >>> > > > >>>> Hi Bill, > >>>> > >>>> Works beatifically! And no bash pipe! > >>>> > >>>> $ raku -ne '.say if $++ == 3|2|5' Lines.txt > >>>> Line 2 > >>>> Line 3 > >>>> Line 5 > >>>> > >>>> What is `$++`? > >>>> > >>>> -T > >>>> > > > > On 2020-08-31 16:36, yary wrote: > >> $ by itself is an anonymous variable, putting ++ after starts it at 0 > >> (hmm or nil?) and increments up. > >> > >> By putting the plus plus first, ++$, it will start at 1, thanks to > >> pre-increment versus post increment > >> > > > > Hi Yary, > > > > Excellent instructions! It is a counter. I found > > it over on > > > > https://docs.raku.org/perl6.html > > > > with a search on `$++`. But I had to pick it up > > from "context" > > > > > > > > $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++," ", ++$, " ", $i, > > "\n";}' > > 0 1 "a" > > 1 2 "b" > > 2 3 "c" > > > > Question: does the counter restart after its use, or do > > I need to do it myself? > > > > -T > > > > To answer my own question. It resets itself: > > $ p6 'my @x=<"a" "b" "c">; for @x -> $i { print $++, " ", ++$, " ", $i, > "\n" }; print "\n", $++, "\n";' > 0 1 "a" > 1 2 "b" > 2 3 "c" > > 0 > > > > -- > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > Computers are like air conditioners. > They malfunction when you open windows > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >