Front page | perl.perl6.users |
Postings from September 2020
Re: print particular lines question
Thread Previous
|
Thread Next
From:
ToddAndMargo via perl6-users
Date:
September 1, 2020 00:01
Subject:
Re: print particular lines question
Message ID:
7b64d1c9-27c5-d361-11f1-7b86f5af0690@zoho.com
On 2020-08-31 16:57, ToddAndMargo via perl6-users 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-users@perl.org <mailto:perl6-users@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
>
>
>
perl6.++.counters.txt
++ counters:
$++ adn ++$ are both anonymous variables
`$++` is a counter that start at zero and increments by 1
`++$` is a counter that start at one and increments by 1
and the reset themselves.
For example:
$ 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
Thread Previous
|
Thread Next