in reply to EOF in string


Using Here documents can cause you alot of grief if you are not careful. They don't seem to have all of the conveniences that were built into Perl (ie. ignoring whitespace). I always found out if I use a Here doc. then I can't put any whitespace before any of the sentence. Everything in the here doc. must be left justified. What has bitten me a few times, is having an extra space at the close of my here doc. I think this is probably your problem. Use a good text editor like vim and it should help you catch these.

HTP
-Dru

Replies are listed 'Best First'.
Re(2): EOF in string
by dmmiller2k (Chaplain) on Dec 27, 2001 at 20:37 UTC
    Using Here documents can cause you alot of grief if you are not careful.

    You have to know what to expect. HERE docs originated in UNIX shell scripting. The shell, upon detecting a '<<' token, actually seeks ahead in the script file itself until it finds the end token (here, 'text'), and then it writes the intervening lines into a temp file and runs the command line containing with the '<<end_token' construct replaced by simple input redirection from that file.

    This allows including input data in the script itself, rather than requiring separate files, which have the potential for getting out of sync.

    Perl attempts to simulate the same effect, but in an improved way (e.g., the entire HERE doc is treated as though it were surrounded with whatever kind of quotes, if any, surround the end token). Perl does not necessarily use a temp file for each HERE doc, but it helps to think of them as though it did just that. The end token must be the first and only thing on its line or it will be treated as part of the content.

    Within a HERE doc, line endings are treated just like any other character, much the same as if an external file were read using the sequence:

    undef $/; # newlines are not record separators anymore $_ = <>; # slurp the whole file in as one big string

    BTW, it is established convention to use all uppercase characters for the end token.

    dmm

    You can give a man a fish and feed him for a day ...
    Or, you can
    teach him to fish and feed him for a lifetime