-
Using HEREDOC for adding a multi-line string to the configuration file with task 'loader', group => 'testing', sub {
my $file = '/boot/loader.conf';
append_if_no_such_line $file, <<~ "LOADER";
kernel="kernel"
bootfile="/boot/kernel/kernel"
LOADER
}; Here I'm passing HEREDOC as the function's second argument. Task fails with:
Note the The construct works in Perl scratch file. Do I need to create an issue about it? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
HEREDOCs should work in general. Rex code is just Perl code, there's no distinction. The The problem here is that the ending delimiter That being said, in general I would not recommend using the
Checking the presence of a multiline input while operating on a line-by-line basis would certainly not work as expected. It would fail to detect whether the content is already there or not, and just append it anyway each time this task is executed. To append two lines, call append_if_no_such_line $file, q(kernel="kernel");
append_if_no_such_line $file, q(bootfile="/boot/kernel/kernel"); Alternatively, for best experience, I would recommend using |
Beta Was this translation helpful? Give feedback.
-
I also didn't know about |
Beta Was this translation helpful? Give feedback.
HEREDOCs should work in general. Rex code is just Perl code, there's no distinction.
The
Compile time errors
message suggests that Rex receives invalid Perl code somehow. When loading theRexfile
uponrex
execution, it is treated as a perl module named__Rexfile__
. This helps avoiding to execute invalid code, by detecting them early (and offloads the whole check to standard perl).The problem here is that the ending delimiter
LOADER
is indented with 8 spaces, while the previous lines are indented with single tabs. I could reproduce the initial error, but when I made the HEREDOC indentation correct, it worked for me as expected.That being said, in general I would not recommend using the
a…