On Sat, Nov 14, 2020 at 1:07 PM ToddAndMargo via perl6-users <perl6-us...@perl.org <mailto:perl6-us...@perl.org>> wrote:

    On 2020-11-14 06:00, Brad Gilbert wrote:
     > The purpose of `spurt` is to:
     > 1. open a NEW file to write to
     > 2. print a single string
     > 3. close the file
     >
     > If you are calling `spurt` more than once on a given file, you
    are doing
     > it wrong.

    You are forgetting that spurt comes with an `:append` option.

     > If you give `spurt` an array, you are probably doing it wrong
     > unless you want the array turned into a single string first.

    Ya, doing things the hard way.



On 2020-11-14 11:51, Brad Gilbert wrote:
Actually no I'm not “forgetting that spurt comes with an `:append` option”.
That is a slightly different use case.
It is where you are appending to an existing file once, and then never touching it again.

(Or maybe you might be touching it again in a few hours.)

---

Given that this is what you wrote:

     unlink( $Leafpadrc );
    for @LeafpadrcNew -> $Line  { spurt( $Leafpadrc, $Line ~ "\n", :append ); }

I want to know how this is the hard way:

     given $Leafpadrc.IO.open(:w) {
         for @LeafpadrcNew -> $Line  { .put: $Line }
         .close;
     }

or

     given $Leafpadrc.IO.open(:w) -> $*OUT {
         for @LeafpadrcNew -> $Line  { put $Line }
         $*OUT.close;
     }

or

     given $Leafpadrc.IO.open(:w) -> $*OUT {
         .put for @LeafpadrcNew;
         $*OUT.close;
     }

or

     given $Leafpadrc.IO.open(:w, :!out-buffer) -> $*OUT {
         .put for @LeafpadrcNew;
     }


I was saying I was doing it the hard way, not you.

Wonderful examples.  Thank you!

Reply via email to