CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Here document - recieved error and not sure how to resolve!

 



yoplocheo
Novice

Dec 19, 2015, 4:48 AM

Post #1 of 6 (1702 views)
Here document - recieved error and not sure how to resolve! Can't Post


Code
#!c:/Perl/bin/perl.exe 
$now=locatime;
print "Content-type: text/html\n\n";
print <<EOF;
<html><head><title>KJ</title></head>
<body bgColor="lightgreen">
<div align="Center"><h1> Sup bow to the sweglord KJ!!</h1>
<img src="https://etcetc linkforpic">
<h2>Rite now it's $now. </h2></div>
</body>
</html>
EOF

and i got:
Having no space between pattern and following word is deprecated at CGI_test.pl line 5.
Bareword found where operator expected at CGI_test.pl line 7, near "<h1> Sup"
(Missing operator before Sup?)
Bareword found where operator expected at CGI_test.pl line 9, near "<h2>Rite"
(Missing operator before Rite?)
syntax error at CGI_test.pl line 5, near "html>"
Can't find string terminator "EOF" anywhere before EOF at CGI_test.pl line 12.

Can someone help me decipher these errors? Thank you!!


FishMonger
Veteran / Moderator

Dec 19, 2015, 7:37 AM

Post #2 of 6 (1692 views)
Re: [yoplocheo] Here document - recieved error and not sure how to resolve! [In reply to] Can't Post

Your code works for me without any errors. Are you sure you ran the same version of the script?


BillKSmith
Veteran

Dec 19, 2015, 8:44 AM

Post #3 of 6 (1685 views)
Re: [yoplocheo] Here document - recieved error and not sure how to resolve! [In reply to] Can't Post

I am unable to duplicate your problem with perl v5.20.2.

You should always use strict and warnings (especially when you are having a problem). It would have alerted you to the typo in localtime.

In my version of the perl documentation, here doc is documented in perlop under quote-like operators. It indicates that your syntax is valid for variable interpolation (same as double quotes). However, a preferred syntax explicitly specifies the required quoting.

Code
print << "EOF";

Good Luck,
Bill


yoplocheo
Novice

Dec 21, 2015, 6:52 PM

Post #4 of 6 (1587 views)
Re: [BillKSmith] Here document - recieved error and not sure how to resolve! [In reply to] Can't Post

Hi, resolved that typo and now as it stands

Code
#!c:/Perl/bin/perl.exe 
use warnings;
use strict;
$now=localtime;
print "Content-type: text/html\n\n";
print <<EOF;
<html><head><title>KJ</title></head>
<body bgColor="lightgreen">
<div align="Center"><h1> Sup bow to the sweglord KJ!!</h1>
<img src="https://thelinkhere">
<h2>Rite now it's $now. </h2></div>
</body>
</html>
EOF

and i got:
Global symbol "$now" requires explicit package name at CGI_test.pl line 4.
Can't find string terminator "EOF" anywhere before EOF at CGI_test.pl line 6.

Why does my version of Perl not recognise the here document? And what does the first error mean? Please help!!


BillKSmith
Veteran

Dec 21, 2015, 9:13 PM

Post #5 of 6 (1580 views)
Re: [yoplocheo] Here document - recieved error and not sure how to resolve! [In reply to] Can't Post


Quote
The terminating string must appear by itself (unquoted and with no surrounding whitespace) on the terminating line.


You probably have whitespace after your EOF. I can duplicate the error by appending a single space.

Under strict, you must declare your variables.


Quote
my $now=localtime;

Without the 'my', perl thinks $now is a global variable.
Good Luck,
Bill


yoplocheo
Novice

Dec 21, 2015, 11:28 PM

Post #6 of 6 (1576 views)
Re: [BillKSmith] Here document - recieved error and not sure how to resolve! [In reply to] Can't Post

Okay noted that too thank you!!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives