Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Why do here-docs have to end with a newline, not EOF?

by Cody Pendant (Prior)
on May 12, 2008 at 01:44 UTC ( #686021=note: print w/ replies, xml ) Need Help??


in reply to Re: Why do here-docs have to end with a newline, not EOF?
in thread Why do here-docs have to end with a newline, not EOF?

If the terminating identifier is on the last line of the program, you must be sure there is a newline after it
...but if there's a newline, then it isn't the last line, is it? Something of a documentation bug there. It would be better expressed as "the terminating identifier isn't allowed to be the last line".


Nobody says perl looks like line-noise any more
kids today don't know what line-noise IS ...


Comment on Re^2: Why do here-docs have to end with a newline, not EOF?
Re^3: Why do here-docs have to end with a newline, not EOF? ("last line")
by tye (Cardinal) on May 12, 2008 at 03:55 UTC
    ...but if there's a newline, then it isn't the last line, is it?

    Newline is traditionally a line terminator not a line separator. But even if you consider newline a line separator, then it is still a bit of a stretch to call the 0 characters after the final newline "a line". I think you have been mislead by quirks of notepad (or its kin) which shows space for a line below the last line since that space is where the cursor goes when you press the final ENTER.

    Certainly, <> won't read "a line" after a final newline in a file (it won't read anything, other than "end of file"). Now, if the last newline in a file is followed by more characters, then the historical view would be to consider that "a partial line" or "an unterminated line" or similar terminology. Traditionally, vi would refuse to create such files and if you used vi to edit such a file and saved any changes, vi would add a final newline silently (this has changed with newer vi replacements like, for example, vim).

    It would be better expressed as "the terminating identifier isn't allowed to be the last line".

    Better to change the verbage to not rely on either view of what "last line" means. Perhaps:

    If the terminating identifier is at the very end of the program without even a newline after it, then Perl will give the warning Can't find string terminator "END" anywhere before EOF. So be sure to include a newline immediately after the terminating identifier.

    - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://686021]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2014-09-18 20:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (124 votes), past polls