Talk:Here document

Latest comment: 16 days ago by Polluks in topic Please add history

Pronounce

edit

Does anybody know - is it pronounced "hear dok" or "heh red oc" (sorry for bad attempts at spelling phonetically!) 213.253.35.7 13:08, 20 September 2006 (UTC)Reply

While I haven't heard it said often, it's always been "hear dok" (two syllables), presumably because it's a contraction of "here document". Mairi 17:10, 20 September 2006 (UTC)Reply

todo ;; add 'Nowdoc' to PHP section

edit

I don't have much knowledge of this topic, perhaps someone who does could add the distinction between 'Heredoc' and 'Nowdoc' in PHP? They're delimited and behave slightly differently. 196.210.216.244 (talk) 03:48, 5 July 2010 (UTC)Reply

reference: http://www.php.net/manual/en/language.types.string.php

todo ;; add interpolation

edit

add content on meaning of interpolation drefty.mac 04:05, 27 October 2006 (UTC)Reply

Back to the future!

edit

I really like the back to the future example for windows power shell (whoever did that). It's funny and very creative. Unfortunately, it's also quite long. I hate to ask, but can you please cut it down substantially? At least so it is at least close to the size of the other examples. Thanks! dr.ef.tymac 19:48, 24 November 2006 (UTC)Reply

Never mind about shortening it, in reconsideration, the perl example is long also. But still, a more straightfoward example seems appropriate. It just seems like a bit much to demonstrate the difference between the two output results. dr.ef.tymac 19:51, 24 November 2006 (UTC)Reply

"Here" ??

edit

What does the word "Here" refer to? or what's its etymology? Dofstead 17:25, 6 March 2007 (UTC)Reply

Probably here as in "a complete document right here". As opposed to theredoc (just found this myself: [1]). 193.143.216.169 11:54, 11 June 2007 (UTC)Reply

Too wide definition

edit

The article defines "here" documents as convenient multi-line string literals, and gives examples including Python's triple-quoted strings. I am almost sure this is incorrect. In Bourne shell, Perl and I guess a few more, the essential feature of a here document is that it isn't a string literal! It is an input stream, like a temporary file containing that string. It's indented to be fed as standard input to some external command. The tr(1) example in the article is typical. JöG (talk) 11:01, 16 February 2008 (UTC)Reply

...and I guess that in PHP everything is heredoc by default, until you introduce any code with "php" tags. --Kubanczyk (talk) 22:37, 29 April 2008 (UTC)Reply
JöG is correct. Almost everything in this article is wrong, because heredocs in the shell aren't string literals, they are file literals ... then perl borrowed the syntax but used it for string literals. Calling Python's """...""" literals "here documents" is stupid, but this misuse of the terminology has even found its way into the Python page. -- 98.108.206.178 (talk) 11:06, 29 March 2011 (UTC)Reply
I agree. I would propose to narrow the definition to constructs where the user can designate an arbitrary, custom string as a tag, and then have all the lines up to that tag are included in the string. This will eliminate the Python triple-quoted strings, since triple quote is not a custom string. --208.80.119.67 (talk) 00:59, 7 September 2011 (UTC)Reply

JöG, thank you for the fabulous insight! Heredocs are significantly subtler and distinct concept from simple multiline string literals, which I hadn’t realized until reading your comment and then the bash docs. I have accordingly substantially revised and cleaned up the article as of this edit. It still has unnecessary, verbose examples, but it’s a fair sight better than before. Significantly, I have corrected the definition, and made a clear distinction between stream/file literals, on the one hand, and string literals with similar syntax, on the other. I’ve also moved content inappropriate to this page (like Python triple-quoted strings, which are not heredocs by any reasonable definition) to string literal. Hope it looks better, and thanks again!

—Nils von Barth (nbarth) (talk) 13:51, 31 August 2013 (UTC)Reply

History of the concept?

edit

Does anyone know the history of the heredoc - who thought of the heredoc? what was the first implementation? etc? Kwertii (talk) 09:46, 7 August 2008 (UTC)Reply

It is a Unix concept. Unix was originally sold to AT&T management as an office tool. Thus the implementation of Unix contains a number of text processing tools for formatting, etc., such as the boilerplate input found in this 'here document'; this arose in the 1970s. --Ancheta Wis (talk) 04:30, 19 July 2009 (UTC)Reply
What ridiculous drivel. The heredoc was introduced in UNIX but it had nothing to do with "office tools" or "text processing tools" -- it was a feature of the Bourne shell, allowing inline definition of temp files. -- 98.108.206.178 (talk) 11:01, 29 March 2011 (UTC)Reply
I see it in V7, but not in V6, sh(1). http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/man/man1/sh.1. I think this (or better) should be in the article. 91.154.87.201 (talk) 14:48, 23 March 2012 (UTC)Reply

delimiting identifier in string literal

edit

Isn't there a vulnerability of the delimiting identifier accidentally occurring within the string literal? --Abdull (talk) 23:07, 27 January 2010 (UTC)Reply

No, "literals" are compile-time constructs in the source code. A string literal only serves to represent a sequence of characters. At runtime it is just a sequence of characters like any other string. "Vulnerabilities" which are runtime things therefore are not relevant. --208.80.119.67 (talk) 01:01, 7 September 2011 (UTC)Reply

Dreadful, tedious examples!

edit

These examples are absolutely awful! They're long and tedious and pretty much worthless. If anyone actually needed such language-specific detail of how Powershell or Perl or some other language implemented all the various bells, whistles and go-fasters in its version of a here document, it is ridiculous to imagine that this is where they'd look to find it. The whole article appears to be the hodgepodge result of the fans of these various languages not wanting to be outdone by fans of the competing languages in listing all the remarkable reasons why their favorite language is best. This just doesn't need to be here. If no one objects in the next few days, I'm going to delete a lot of this junk and trim the article down (unless someone else beats me to it!) Msnicki (talk) 08:07, 24 October 2010 (UTC)Reply

I've added the "External links" section, with a link to a Rosetta Code task on here documents that fulfils the same function as the list of language examples here. But is that enough to warrant removing the examples in this entry ? --Paddy (talk) 11:27, 7 September 2011 (UTC)Reply

Bug in PHP ?

edit

I don't know PHP but, looking at:

echo strtolower($toprint);

I would expect the output to be converted in lower case and look like:

hey joe smith! you can actually assign the heredoc section to a variable!

rather than the current:

Hey Joe Smith! You can actually assign the heredoc section to a variable!

Am I wrong?

I have no way to test it... Jack-cnv (talk) 12:00, 28 February 2012 (UTC)Reply

No sir, you are entirely correct! In fact, I only came here to see if there had been any discussion of it. I have just tested it with PHP 5.4 on Linux, standard configuration, and it's total nonsense - strtolower would drop all the uppercase letters down. strtolower also has absolutely sod all to do with an example of heredoc strings, so I shall be removing it entirely from the example. -Joey- (talk) 11:05, 29 March 2012 (UTC)Reply

TCL

edit

"Tcl has no special syntax for heredocs, because the ordinary string syntaxes already allow embedded newlines and preserve indentation."

This is a non-sequitur. The ordinary string syntaxes of Perl, Ruby and PHP allow embedded newlines and preserve indentation; yet all three also support heredoc syntax.

Given that Tcl doesn't support heredocs, why are there Tcl examples at all? — Preceding unsigned comment added by 109.155.240.244 (talk) 14:20, 5 March 2012 (UTC)Reply

Windows Command Shell

edit

I fail to see how the Windows Command Shell example is useful as it does not provide an example of preserving whitespace and line breaks (it does show how to temporarily change the value of a variable, which is cool, but is also completely unrelated to the traditional use of a heredoc). I am looking for a work-around myself, otherwise I would suggest a fix (and I will post one if I do figure it out), however the example in its current form does more harm than good, IMHO. JoeCasadonte (talk) 18:24, 22 July 2013 (UTC)Reply

Here's a working example:
Given a perl script named "echolines.pl" consisting of the following (to simulate a 'real' program):
use strict;
use warnings;

while (<>) {
	chomp;
	print qq(<$_>\n);
}
and a batch file named "testme.bat" containing:
@echo off

set FOO=foo
set BAR=bar
set BAZ=baz

echo %FOO%^
&echo %BAR%^
&echo %BAZ%|perl echolines.pl
running it produces the expected output:
C:\>testme
<foo>
<bar>
<baz>
Care with whitespace must be taken to ensure it all works correctly with no stray spaces anywhere. Specifically: each end-of-line should be a caret (^) followed by a newline, the subsequent lines must begin immediately with the ampersand (&) and the last line must have the pipe starting immediately after the last item to be sent. Failing to do this will result in missing parameters or extra whitespace before and after the parameters. JoeCasadonte (talk) 20:01, 22 July 2013 (UTC)Reply
I agree that the current example is not useful. But the fact you can write a .cmd file that uses individual commands to create the same output you could have gotten with a shell that provides a genuine here document is not the same as actually having a genuine here document facility. So I'm not sure there's any example that would make happy as anything but a sample work-around. I think the opening words of this section, "Windows does not have an equivalent to Here documents", tell everything there is to say about here docs under cmd.exe that's encyclopedic and not just how-to: They don't exist. Done. Msnicki (talk) 20:44, 22 July 2013 (UTC)Reply
I would concur, either fix the work-around or get rid of it. If the correct thing to do is to remove the work-around, would it be appropriate to say something like "It doesn't exist under Windows, but if you want a work-around go look here" and provide a link to a StackOverflow question (specifically http://stackoverflow.com/questions/1015163/)? JoeCasadonte (talk) 00:09, 23 July 2013 (UTC)Reply
I am going to replace the current example with the example I provide above unless there are any objections. JoeCasadonte (talk) 14:19, 16 August 2013 (UTC)Reply
Since there were no objections I changed the main page and the change was reverted. I thought the whole point of the Talk pages was to hash this out before the article was changed? I wish you, Msnicki, would have responded to the talk page when I asked for feedback. In any event, I don't agree that it's better to have no example. So, how do we come to a resolution on this? JoeCasadonte (talk) 15:29, 23 August 2013 (UTC)Reply
I did give you feedback: "So I'm not sure there's any example that would make happy as anything but a sample work-around." Msnicki (talk) 15:34, 23 August 2013 (UTC)Reply
And then I continued the conversation, including proposing a path forward, which was ignored. I'm new to editing Wikipedia articles - how are disagreements handled when there are only two people with opinions? JoeCasadonte (talk) 17:10, 23 August 2013 (UTC)Reply
Okay, well, go ahead and revert me to put it back if you like. I won't take offense. I don't feel so strongly that I would revert you back. I do my best to play well with others. Msnicki (talk) 17:38, 23 August 2013 (UTC)Reply
I think I like the new edits; I'll look again later to see if my example has a place here now.JoeCasadonte (talk) 13:41, 28 August 2013 (UTC)Reply
edit

I vote for this TODO - Aaronchall (talk) 18:05, 24 May 2016 (UTC)Reply

edit

Hello fellow Wikipedians,

I have just modified one external link on Here document. Please take a moment to review my edit. If you have any questions, or need the bot to ignore the links, or the page altogether, please visit this simple FaQ for additional information. I made the following changes:

When you have finished reviewing my changes, you may follow the instructions on the template below to fix any issues with the URLs.

This message was posted before February 2018. After February 2018, "External links modified" talk page sections are no longer generated or monitored by InternetArchiveBot. No special action is required regarding these talk page notices, other than regular verification using the archive tool instructions below. Editors have permission to delete these "External links modified" talk page sections if they want to de-clutter talk pages, but see the RfC before doing mass systematic removals. This message is updated dynamically through the template {{source check}} (last update: 5 June 2024).

  • If you have discovered URLs which were erroneously considered dead by the bot, you can report them with this tool.
  • If you found an error with any archives or the URLs themselves, you can fix them with this tool.

Cheers.—InternetArchiveBot (Report bug) 11:57, 1 April 2017 (UTC)Reply

Please add history

edit

When is this technique from? 2020s? 1980s? First implementation, who came up with it? Would be nice to know... 104.172.234.209 (talk) 18:17, 30 January 2023 (UTC)Reply

Indeed, since 1979. Polluks 08:01, 23 October 2024 (UTC)Reply