Documentation for routine
spurt assembled from the following types:
From Independent routines
multi spurt(IO() $path, |c)
The encoding with which the contents will be written.
Boolean indicating whether to append to a (potentially) existing file. If the file did not exist yet, it will be created. Defaults to
Boolean indicating whether to fail if the file already exists. Defaults to
# write directly to a file spurt 'path/to/file', 'default text, directly written'; # write directly with a non-Unicode encoding spurt 'path/to/latin1_file', 'latin1 text: äöüß', :enc<latin1>; spurt 'file-that-already-exists', 'some text'; # overwrite file's contents: spurt 'file-that-already-exists', ' new text', :append; # append to file's contents: say slurp 'file-that-already-exists'; # OUTPUT: «some text new text␤» # fail when writing to a pre-existing file spurt 'file-that-already-exists', 'new text', :createonly; # OUTPUT: «Failed to open file /home/camelia/file-that-already-exists: file already exists …»
method spurt(IO::Path:D: $data, :$enc, :$append, :$createonly)
Opens the file path for writing, and writes all of the
$data into it. File will be closed, afterwards. Will
fail if it cannot succeed for any reason. The
$data can be any
Cool type or any
Blob type. Arguments are as follows:
:$append— open the file in
appendmode, preserving existing contents, and appending data to the end of the file.
failif the file already exists.
multi method spurt(IO::Handle:D: Blob $data, :$close = False) multi method spurt(IO::Handle:D: Cool $data, :$close = False)