At times even little things may prove confusing, thus here's my question (please bare with me since the topic is not overly exciting ;-)

Generally, I'm a fan of delimiting text in my code with qq| |; or qq~ ~; Here's an example:
my $text = qq~ First line Second line ~;
print $text;

However, lately, I started to notice (i'm wondering if I simply ignored that aspect of Perl before) some monks using alternative delimiters such as <<. Out of curiosity, I gave it a try in one of my existing scripts. However, this failed to work miserably... as will be shown below.

Here's a sample tiny script that works:
print <<END Hello there! This is a test! END


Here, I attempt to add an extra line just below print:
print <<END Hello there! This is a test! END my $i;

and this failes with the error:
syntax error at text_delim.pl line 11, near "my " Global symbol "$i" requires explicit package name at text_delim.pl lin +e 11.
Yet, when I add a ; below the line containing closing END, the error disappears and I can run script well.
print <<END Hello there! This is a test! END ; my $i;
Strange thing is, however, that I always assumed there should be no ';' after the closing line/word of the << text delimiter. Since, also a code like this always worked for me (strangely enough, I never noticed or paid much attention to the ';' after the first <<END either):
print <<END; Hello there! This is a test! END my $i;
Could anyone explain me why there should be a ';' in there at all? And also, why is it permissable to place ';' in either of the two places. What's the difference? Thanks.

"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith

In reply to alternative text delimiters by vladb

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.