Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by turo (Friar)
on May 12, 2008 at 00:11 UTC ( #686007=note: print w/replies, xml ) Need Help??


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

I'm using perl 5.8.8 version for testing your little snippet and it works well. I've executed it with and without the final LF; in unix and in MSDOS format (with CR-LF); and the snippet still works well ...

perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'

Replies are listed 'Best First'.
Re^2: Why do here-docs have to end with a newline, not EOF?
by ikegami (Pope) on May 12, 2008 at 01:05 UTC

    Really? I can reproduce the OP's results on WinXP and Linux.

    WinXP, Perl 5.8.8, ActivePerl 820

    >perl -e"print qq{print <<ENDHERE\nabc\nENDHERE}" > test.pl >perl test.pl Can't find string terminator "ENDHERE" anywhere before EOF at test.pl +line 1. >perl -e"print qq{print <<ENDHERE\nabc\nENDHERE\n}" > test.pl >perl test.pl abc >

    Linux, Perl 5.8.4

    $ perl -e'print qq{print <<ENDHERE\nabc\nENDHERE}' > test.pl $ perl test.pl Can't find string terminator "ENDHERE" anywhere before EOF at test.pl +line 1. $ perl -e'print qq{print <<ENDHERE\nabc\nENDHERE\n}' > test.pl $ perl test.pl abc $

    If I were to guess, I'd say the parser looks for <"\nENDHERE\n"> instead of <"\nENDHERE" followed by either "\n" or end of file>, and it does so because it's easier and because every line is suppose to end with a line feed in unix.

      yeep ... my editor was adding the final '0a' in the file without consulting me :-S ...
      perl -Te 'print map { chr((ord)-((10,20,2,7)[$i++])) } split //,"turo"'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2020-08-13 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which rocket would you take to Mars?










    Results (68 votes). Check out past polls.

    Notices?