I am writing a very simple script to create template chapters for epub ebooks. Basically you run the script with a parameter that tells it how many chapters you want and it creates those, along with an appropriate series of entries to copy in to the OPF.
To do this I am using a 'heredoc' to hold the boilerplate template, which will be repeated for each chapter, using s///g to replace the various **** place holders as needed:
my $chapter_template=<<HERE; <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/T +R/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="application/xhtml+xml +; charset=utf-8" /> <link type="text/css" rel="stylesheet" href="..\css\style_shee +t.css" /> <title>*****ebook title goes here*****</title> <meta name="author" content="*****ebook author name(first, las +t) goes here*****" /> </head> <body> <h2 class="ebook" id="LinkID*****current link goes here*****"> +Chapter *****current chapter number goes here*****</h2> <p class="ebook">*****ebook content goes here onwards*****</p> </body> </html> HERE
As I understand it everything between '<<HERE;' and 'HERE' should be stored exactly as it appears in the script, ignoring any new lines or other formatting which might clash with native Perl statements. However when I run this I get a message saying 'unrecognised escape \s passed through at line 32', which seems to suggest the interpreter is reading and trying to execute the heredoc contents instead of simply storing them in the specified scalar.
Have I got the wrong end of the stick somewhere? Obviously I could just assign the heredoc contents directly to a variable, using escapes to insert the corresponding new lines and tabs and html formatting. However that gets very confusing very quickly and I thought the heredoc approach was meant to give a simpler 'wysiwig' method for doing this.
In reply to 'Here Documents' and unrecognized escapes by morelenmir
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |