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

Hi Monks,

I have used the Here document in part of my function to print multiple statements.When i execute the here document part only as a stand-alone script,it prints the expected output.However,when i use the here document within a function , I get the following error :

"Can't find string terminator "END" anywhere before EOF at generateTAFLib.pl line 110."

The codelet is

sub test(){ #variable declarations #some code print <<'END'; output END #some code }

I checked the perfaq and verified that the code conforms to the here document requirements.Can't figure out why i get this error.

The output spans a lot of lines and so have not mentioned it here.

Thanks in advance.

Replies are listed 'Best First'.
Re: HERE document string terminator error
by 1Nf3 (Pilgrim) on Jul 10, 2009 at 08:01 UTC

    I would guess that you have left a space after the END, or the whole sub is indented. The terminator must be all alone on a separate line for the whole thing to work. Check it.

    Regards,
    Luke

      I guess that was it!the space after the END. got it working now. Thanks!
Re: HERE document string terminator error
by moritz (Cardinal) on Jul 10, 2009 at 07:49 UTC
    The piece of code you posted here works fine for me.

    So please post something that really exhibits the error, otherwise we can't help you.

Re: HERE document string terminator error
by pKai (Priest) on Jul 10, 2009 at 08:27 UTC

    What moritz said.

    Nonetheless you might check for trailing whitespace behind the END terminator, which is an easy way to trigger your error.

    Update: Oops, heavy delay on cross post with 1Nf3.