I'm using a dequoting function from the Perl Cookbook to make large, indented here-docs look nicer. Here's some code:
my $tempscript = dequote<<' END'; !!! some text END sub dequote { local $_ = shift; my ($white, $leader); if (/^\s*(?:([^\w\s]+)(\s*).*\n)(?:\s*\1\2?.*\n)+$/) { ($white, $leader) = ($2, quotemeta($1)); } else { ($white, $leader) = (/^(\s+)/, ''); } s/^\s*?$leader(?:$white)?//gm; return $_; }

This code results in a syntax error at the end of the here-doc. The problem is that Perl doesn't know about dequote yet. Making the dequote usage more explicit (&dequote, dequote()) doesn't help in this case. Two things work: putting the dequote function before its first usage, or using a prototype.

But then things get a little more complicated. In the real code, dequote is in a utility script, separate from where it's used. I'm exporting it and useing the utilities script before trying to call the function, but I still get the syntax error. The only thing that works is if I explicitly specify the package before each call to dequote. I'd rather not do this.

I don't have problems with any other functions in my utilities script. Do functions behave differently when used in here-docs?

---
A fair fight is a sign of poor planning.


In reply to Prototyping functions used in here-docs by Sprad

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.