Documentation for routine spurt
Documentation for routine spurt, assembled from the following types:
sub spurt(, ,Str : = 'utf8',Bool : = False,Bool : = False,Bool : = False--> Bool )
Writes the indicated contents (2nd positional parameter,
$what) to the location indicated by the first positional parameter,
$where (which can either be a string or an
IO::Path object). To write to an
IO::Handle, use the print method.
If a file needs to be opened for writing, it will also be
True on success, or the appropriate
Failure if something went wrong.
These named parameters are optional and only have meaning if the first positional parameter was not an
The encoding with which the contents will be written.
Open the file in binary mode.
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";# append to a pre-existing file#spurt "file_already_exists", "some text";#spurt "file_already_exists", "new text", :append;#slurp "file_already_exists"; # some text␤new text# fail when writing to a pre-existing file#spurt "file_already_exists", "new text", :createonly;CATCH ;# OUTPUT: «X::Cannot::Empty: Cannot pop from an empty Array␤»
multi method spurt(IO::Path: Blob , :, |c)multi method spurt(IO::Path: Cool , :, |c)
$contents to this path, like spurt.