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


Hi Monks

When i want to compile the following code,it shows an error "Can't find string terminator "EOHTML" anywhere before EOF at ajay.pl line 18."
#!C:\Perl\bin\perl.exe -w use strict; use CGI; # or any other CGI:: form handler/decoder use CGI::Ajax; my $cgi = new CGI; my $pjx = new CGI::Ajax( 'exported_func' => \&perl_func ); print $pjx->build_html( $cgi, \&Show_HTML); sub perl_func { my $input = shift; # do something with $input my $output = $input . " was the input!"; return( $output ); } sub Show_HTML { my $html = <<EOHTML; <HTML> <BODY> Enter something: <input type="text" name="val1" id="val1" onkeyup="exported_func( ['val1'], ['resultdiv'] );"> <br> <div id="resultdiv"></div> </BODY> </HTML> EOHTML return $html; }

Plz any one suggest me, what is the wrong with it?

Regd's
sanjay

Replies are listed 'Best First'.
Re: Why the following code shows a compilation error?
by ccn (Vicar) on Dec 19, 2008 at 09:50 UTC
    No any spaces allowed before and after the string terminator (EOHTML). Strip those and it will compile.

    And carriage return is a must if the string terminator is at the last line of a script.

    see perldoc perlop (Quote-Like-Operators)

Re: Why the following code shows a compilation error?
by ikegami (Patriarch) on Dec 19, 2008 at 09:50 UTC
    spaces. The terminator must be the only thing on the line. It can't be prefixed or suffixed with spaces.
Re: Why the following code shows a compilation error?
by Anonymous Monk on Dec 19, 2008 at 10:30 UTC
Re: Why the following code shows a compilation error?
by svenXY (Deacon) on Dec 19, 2008 at 09:57 UTC
    Hi,
    you can work with indented heredocs by using the recipe 1.12 from the Perl Cookbook
    Regards,
    svenXY

    update: removed the link, adjusted it to point at O'reilly instead. Sorry.

      I wonder if that link leads to copyright abuse?

        Hi

        Many many thanks for the suggestion. Yes it is a copyright abuse. Now it is working.

        Regd's
        Sanjay
Re: Why the following code shows a compilation error?
by jeffa (Bishop) on Dec 19, 2008 at 21:09 UTC

    What's wrong is a different question than why doesn't it compile. Since you now know why it doesn't compile -- "what's wrong with it" is that it doesn't use a Templating system, such as HTML::Template. If you would use a templating system, then you would not need to embed your HTML into your Perl, and you would avoid having to use tools such as HEREDOCS which force your indentation to be non-uniform. At least HEREDOCS prevent you from having to escape your data, but there is a better way.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)