Drop here docs altogether? (was Re: RFC 111 (v3) Here Docs Terminators (Was Whitespace and Here Docs))
Show me where this fails and I'll shut up about it. Actually, to me this thread underscores how broken here docs are themselves. We already have q//, qq//, and qx// which duplicate their functions far more flexibly. Question: Do we really need here docs? Before you scream "Bloody murder", please read on... The current stumper, which involves problems 1, 2 and 3 is this: if( $is_fitting $is_just ) { die POEM; The old lie Dulce et decorum est Pro patria mori. POEM } I propose that this work out to "The old lie\n Dulce et decorum est\n Pro patria mori.\n" Let's look at what happens if we ignore here docs and instead use qq// instead: if( $is_fitting $is_just ) { die qq/ The old lie Dulce et decorum est Pro patria mori. /; } Solves problem #1, indented terminator, except that it adds two newlines (more later). However, it leaves 2 and 3. Let's try adding in a regexp: if( $is_fitting $is_just ) { (my $mesg = qq/ The old lie Dulce et decorum est Pro patria mori. /) =~ s/\s{8}(.*?\n)/$1/g; die $mesg; } But the dang =~ operator make that ugly and hard to read, and requires a $mesg variable. So let's try RFC 164's approach to patterns then: if( $is_fitting $is_just ) { die subst /\s{8}(.*?\n)/$1/g, qq/ The old lie Dulce et decorum est Pro patria mori. /; } Seems to work for me (and yes I'm working on a prototype of RFC 164's functions). I think we're trying to jam alot of stuff into here docs that maybe shouldn't be jammed in, especially since Perl already has the q// alternatives that are much more flexible. Don't get me wrong, I like here docs and all, but I wonder if it isn't time for them to go? I think I'd actually much rather see a new qh// "quoted here doc" operator that solves these problems than trying to jam them all into the existing shell-like syntax, which is a leftover oddity, really. -Nate
Re: Drop here docs altogether? (was Re: RFC 111 (v3) Here Docs Terminators (Was Whitespace and Here Docs))
At 10:52 AM 9/14/00 -0700, Nathan Wiger wrote: Actually, to me this thread underscores how broken here docs are themselves. We already have q//, qq//, and qx// which duplicate their functions far more flexibly. Question: Do we really need here docs? I have thought this before, but I think the answer is yes, for the circumstance of when the quoted material does or may contain the terminator character. No matter what you pick, you still only have one character as a terminator, and if you're quoting something big and sufficiently general (think Perl code), then it's a pain to check it each time to see if you've stuck in the terminator by mistake. At any rate, this is what I tell my students when they realize that "..." can contain newlines and start to wonder about the raison d'etre of here documents. I think I'd actually much rather see a new qh// "quoted here doc" operator that solves these problems than trying to jam them all into the existing shell-like syntax, which is a leftover oddity, really. -- Peter Scott Pacific Systems Design Technologies
Re: Drop here docs altogether? (was Re: RFC 111 (v3) Here Docs Terminators (Was Whitespace and Here Docs))
Nathan Wiger wrote: Actually, to me this thread underscores how broken here docs are themselves. We already have q//, qq//, and qx// which duplicate their functions far more flexibly. Question: Do we really need here docs? Yes. Try generating lots of HTML, Javascript, Postscript, or other languages without here docs. Example: print CODE_SNIPPET; // this is a javascript function function valid(s) { ... if (var2 = '"')) { // rest of code to be generated later. CODE_SNIPPET There's a chunk of code for which '', "", qq//, qq, qq{}, are all inadequate. This kind of code happens A LOT in web programming. I do not want to have to examine all of my generated strings to see what quoting character I can use this time around, and I do not want to risk breaking my program whenever I change the text in a code snippet ("oops! I added a bracket. gotta change the quoting character!"). -- Eric J. Roode, [EMAIL PROTECTED] print scalar reverse sort Senior Software Engineer'tona ', 'reh', 'ekca', 'lre', Myxa Corporation'.r', 'h ', 'uj', 'p ', 'ts';
Re: Drop here docs altogether? (was Re: RFC 111 (v3) Here Docs Terminators (Was Whitespace and Here Docs))
On Thu, 14 Sep 2000 10:52:16 -0700, Nathan Wiger wrote: We already have q//, qq//, and qx// which duplicate their functions far more flexibly. Question: Do we really need here docs? With your above functions, you always need to be able to escape the string end delimiter. Therefore, you will always have to escape backslashes. You don't need to escape backslashes, or anything else, in a single-quoted here-doc. Here-docs are extremely handy if you have to incorporate text from an external file, which perl is supposed to print out verbatim. Their disadvantage is that they'll always end with a newline. -- Bart.
Re: Drop here docs altogether? (was Re: RFC 111 (v3) Here Docs Terminators (Was Whitespace and Here Docs))
Nathan Wiger wrote: Solves problem #1, indented terminator, except that it adds two newlines (more later). I never found anything later about these extra newlines... so if this idea has merit, it needs to be finished. However, it leaves 2 and 3. Let's try adding in a regexp: if( $is_fitting $is_just ) { (my $mesg = qq/ The old lie Dulce et decorum est Pro patria mori. /) =~ s/\s{8}(.*?\n)/$1/g; die $mesg; } I think $mesg wins up with the value of "1" the way you've coded it. You cured that issue with the RFC 164 syntax for subst, of course, but it could be cured without that, but does require a temp var. I think we're trying to jam alot of stuff into here docs that maybe shouldn't be jammed in Yes, all we need is to recognize the terminator when embedded in white space on its line, and the rest can be handled with "here doc postprocessing functions". Per my somewhat longer reply to Michael Schwern. I agree with need for a multiple character termination sequence for easy to write here docs. -- Glenn = There are two kinds of people, those who finish what they start, and so on... -- Robert Byrne _NetZero Free Internet Access and Email__ http://www.netzero.net/download/index.html
Re: Drop here docs altogether? (was Re: RFC 111 (v3) Here Docs Terminators (Was Whitespace and Here Docs))
On Thu, Sep 14, 2000 at 10:52:16AM -0700, Nathan Wiger wrote: Before you scream "Bloody murder", please read on... I'll wait patiently for the end... if( $is_fitting $is_just ) { die subst /\s{8}(.*?\n)/$1/g, qq/ The old lie Dulce et decorum est Pro patria mori. /; } Seems to work for me (and yes I'm working on a prototype of RFC 164's functions). No, it still has all the problems of any other regex-based solution. If you shift the code right or left, it breaks (due to the \s{8}) and you're back to counting whitespace again. And as Glen pointed out, what about that leading newline? Can I scream now? -- Michael G Schwern http://www.pobox.com/~schwern/ [EMAIL PROTECTED] Just Another Stupid Consultant Perl6 Kwalitee Ashuranse MORONS!
Re: Drop here docs altogether? (was Re: RFC 111 (v3) Here Docs Terminators (Was Whitespace and Here Docs))
Glenn Linderman wrote: I think $mesg wins up with the value of "1" the way you've coded it. Sorry, I missed the placement of the (). $mesg is fine. -- Glenn = There are two kinds of people, those who finish what they start, and so on... -- Robert Byrne ___ Why pay for something you could get for free? NetZero provides FREE Internet Access and Email http://www.netzero.net/download/index.html
Re: Drop here docs altogether? (was Re: RFC 111 (v3) Here Docs Terminators (Was Whitespace and Here Docs))
Michael G Schwern wrote: No, it still has all the problems of any other regex-based solution. If you shift the code right or left, it breaks (due to the \s{8}) and you're back to counting whitespace again. Y'know, I pointed out before why I think this is a superfluous issue. You have to either change your regexp, or change the indentation of your here docs terminator when you move your code around. And counting whitespace is not so hard to justify breaking this: if ( $its_all_good ) { print EOF; Thank goodness this text is centered! I'd really hate for it to left-shift on me. EOF } This should print out the text as shown verbatim. If you want reformatting of any kind, that's what regex's are for. The above is far more flexible, and your problem already has several other solutions, which you have yourself noted. Plus how to address the whole can of worms with tabs - spaces, 4 or 8, trailing too, blank line stripping? Blech. regex. And as Glen pointed out, what about that leading newline? Handled by the regexp, actually (yep I tested it). Can I scream now? Not yet, but I might! :-) -Nate