routine spurt
1 | language documentation Independent routines |
1.1 | (Independent routines) sub spurt |
1.1.1 | Options |
1.1.2 | Examples |
2 | class IO::Path |
2.1 | (IO::Path) method spurt |
3 | class IO::Handle |
3.1 | (IO::Handle) method spurt |
Documentation for routine spurt
assembled from the following types:
language documentation Independent routines
From Independent routines
(Independent routines) sub spurt
Defined as:
multi spurt(IO() , |c)
The $path
can be any object with an IO method that returns an IO::Path
object. Calls IO::Path.spurt
on the $path
, forwarding any of the remaining arguments.
Options
:enc
The encoding with which the contents will be written.
:append
Boolean indicating whether to append to a (potentially) existing file. If the file did not exist yet, it will be created. Defaults to False
.
:createonly
Boolean indicating whether to fail if the file already exists. Defaults to False
.
Examples
# write directly to a filespurt 'path/to/file', 'default text, directly written';# write directly with a non-Unicode encodingspurt '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 filespurt 'file-that-already-exists', 'new text', :createonly;# OUTPUT: «Failed to open file /home/camelia/file-that-already-exists: file already exists …»
class IO::Path
From IO::Path
(IO::Path) method spurt
Defined as:
method spurt(IO::Path: , :, :, :)
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:
:$enc
— character encoding of the data. Takes same values as:$enc
inIO::Handle.open
. Defaults toutf8
. Ignored if$data
is aBlob
.:$append
— open the file inappend
mode, preserving existing contents, and appending data to the end of the file.:$createonly
—fail
if the file already exists.
class IO::Handle
From IO::Handle
(IO::Handle) method spurt
Defined as:
multi method spurt(IO::Handle: Blob , : = False)multi method spurt(IO::Handle: Cool , : = False)
Writes all of the $data
into the filehandle, closing it when finished, if $close
is True
. For Cool
$data
, will use the encoding the handle is set to use (IO::Handle.open
or IO::Handle.encoding
).
Behavior for spurting a Cool
when the handle is in binary mode or spurting a Blob
when the handle is NOT in binary mode is undefined.