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.

"Aure Entuluva!" - Hurin Thalion at the Nirnaeth Arnoediad.

In reply to 'Here Documents' and unrecognized escapes by morelenmir

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.