nysus has asked for the wisdom of the Perl Monks concerning the following question:

I've been playing around some with 'Here' documents. First I tried the following script:
#!/usr/bin/perl -w use strict; use CGI; my $query = new CGI; print <<EOF; <html> <head> </head> <body> Hello. </body> </html> EOF

The above resulted in a Can't find string terminator "EOF" anywhere before EOF at formtest.cgi line 7. Then, on a hunch, I tried:

#!/usr/bin/perl -w use strict; use CGI; my $query = new CGI; &routine; sub routine { print <<EOF; <html> <head> </head> <body> Hello. </body> </html> EOF }

...merely placing the 'Here' document in a subroutine and it worked fine. Can someone please explain this behavior?

Replies are listed 'Best First'.
Re: Here document outside subroutines
by OeufMayo (Curate) on Apr 02, 2001 at 19:08 UTC

    It's a glitch under Win32 systems. You have to add a newline character after your Heredoc end marker.

    <kbd>--
    my $OeufMayo = new PerlMonger::Paris({http => 'paris.mongueurs.net'});</kbd>
      Yup! That was it. Thanks.