Slurp a file




















How do I submit a change to the documentation? How do I keep secret data in my playbook? Docs » slurp - Slurps a file from remote nodes You are reading an unmaintained version of the Ansible documentation. It is used for fetching a base encoded blob containing the data in a remote file.

See also: fetch. The file on the remote system to fetch. This must be a file, not a directory. That is certainly not good. For this we needed an enclosing block, so we added a pair of curly braces around the code-snippet dealing with the file. Creating a slurp function In the third iteration of the code, we create a separate function called slurp that will get the name of the file and return the content as a single string. This allows us to hide the code-snippet at the end of the program or even in a separate file.

It also makes it reusable, so instead of copying it to other places where we might need the same functionality we can just call the slurp function.

This makes the main body of our code much nicer. Path::Tiny An even better solution is to use the Path::Tiny module. It exports the path function that gets a path to a file as a parameter and returns an object. Toggle navigation Perl Maven.

Standard output, standard error and command line redirection Warning when something goes wrong What does die do? This function returns a list of the filenames in the supplied directory.

In list context, an array is returned, in scalar context, an array reference is returned. The following options are available:.

In quiet mode, all errors will be silent. In carp mode, all errors will be emitted as warnings. And, in croak mode, all errors will be emitted as exceptions.

Setting this option to true 1 will also return the. The prefix option is a boolean option, defaulted to false 0. Setting this option to true 1 add the directory as a prefix to the file. See File::Spec. This function reads in an entire file and returns its contents to the caller. In scalar context it returns the entire file as a single scalar. The binmode option is a string option, defaulted to empty ''. If you set the binmode option, then its value is passed to a call to binmode on the opened handle.

Load Comments. What's New. Most popular in Perl. Introduction to Perl Perl Boolean Values. More related articles in Perl.

We use cookies to ensure you have the best browsing experience on our website. Start Your Coding Journey Now!



0コメント

  • 1000 / 1000