in reply to Re: EOF in string
in thread EOF in string
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 ...
|
|---|