> On Aug 25, 2020, at 4:13 PM, yary <not....@gmail.com> wrote:
> 
> > Now, does anyone have a simpler way than using the ".map" above?
> 
> There were a few in the thread!
> 
> Here's my golfing, unlike the others, this preserves the order of the lines 
> (which may or may not be desired)
> 
> raku -ne '.say if $++ == any 6,3,1' line0-10.txt

—snip—

That technique is called the "anonymous state variable", and is documented here:
https://docs.raku.org/language/variables#The_$_variable

I especially favor the `-n` flag for this problem, because we con’t have to 
“slurp” a possibly-large file into memory, and because it enables the `UNIX 
filter` behavior that allows us to specify the filename as a command-line 
argument, instead of having to pipe it in with `cat` (or `type` on Win32).

My version is almost identical, but changing to pre-increment allows you to 
specify the line numbers with the more natural numbering:
raku -ne '.say if ++$ == any(1,3,7);' Lines.txt
Line 1
Line 3
Line 7

-- 
Bruce Gray (Util of PerlMonks)

Reply via email to