On Thu, Aug 27, 2020 at 1:40 PM ToddAndMargo via perl6-users <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:

    On 2020-08-27 13:28, Tobias Boege wrote:
     > On Thu, 27 Aug 2020, ToddAndMargo via perl6-users wrote:
     >> To pick out particular lines:
     >>     $ cat Lines.txt | raku -e '.say for lines()[3,2,5]'
     >>     Line 3
     >>     Line 2
     >>     Line 5
     >>
     >> If it is, it is buried somewhere.
     >>
     >> And what goes inside the ()?  That may seem like a dumb
     >> remark (especially since I live and die in Top Down and
     >> know very well what the () does) but it is a common mistake
     >> I make with lines is forgetting the () when using the [].
     >>
     >
     > How does that mistake manifest? I cannot see a way in which omitting
     > the sub call parentheses in code like that could possibly lead to
    some
     > different behavior.
     >

    Here is does not:

    $ cat Lines.txt | raku -e '.say for lines[3,2,5]'
    Line 3
    Line 2
    Line 5

    And I am having trouble reproducing the issue.  Would
    help my point, no?  I will write back if I find it.
    Usually I forget my mistakes as soon as I figure out
    the right way to do things.

    Now this is getting weird!

    $ cat Lines.txt | raku -ne 'my $x=$_; say $x; for $x.lines()[3,2,5] ->
    $i {say $i;}'

    Line 0
    Nil
    Nil
    Nil
    Line 1
    Nil
    Nil
    Nil
    Line 2
    ...


On 2020-08-27 14:12, yary wrote:
You have an extra semicolon in there -" say $x; for" -

so what happens is for each line
1. it runs "say $x" and thus prints "Line 0" the first time through, since it had read "Line 0" only 2. Then it runs "say $i" for each of $x.lines()[3,2,5] - but $x is only "Line 0" so it says 3 x "Nil"
3. Repeat for "Line 1", etc
-y

But I wanted the extra `;` in there.  I wanted to see
before and after.

Reply via email to