*NOTE*:
sorry I had a few 'syntax' errors in my original post.
I forgot to change '<<' with '<<' which 'cause a few
words in my original post not to appear properly.
Below is my properly formatted post.
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 the closing END, the error
disappears and I can run the 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
|