On Mon, Sep 04, 2000 at 09:32:00PM -0000, Perl6 RFC Librarian wrote:
> Perl6 should ignore any whitespace before the terminator of a heredoc on any
> line. 

Good.  I don't see anything wrong with this.

***BRAIN STORM!***

RFC 162 (http://dev.perl.org/rfc/162.html) wanted to allow indented
here-docs, but had the problem of how to figure out what was code
indentation and what was deliberate text indentation.  For example:

    if( $payment < $they_owe ) {
        print MAIL <<<LETTER;
                        Attention delinquent scum,

            We have noticed that you still owe us money
        which we graciously loaned you in your hour of need.
        Rocco will be by shortly to collect your kneecaps.
LETTER
    }

The RFC proposes a <<< operator which would strip whitespace off the
front of the here-doc.  Problem is preserving indentation.  We can
merge the two.

    if( $payment < $they_owe ) {
        print MAIL <<LETTER;
                        Attention delinquent scum,

            We have noticed that you still owe us money
        which we graciously loaned you in your hour of need.
        Rocco will be by shortly to collect your kneecaps.
        LETTER
    }

<< will notice that the closing 'LETTER' tag is indented and strip
that amount of whitespace off the front.  No regexes, no counting
spaces (you just line it up with the left margin of the text) and it
does what you mean.

In this case...

    print <<FOO;
    text
ooops
    more text
    FOO

Perl will issue a warning because the leftmost margin of the here-doc
text is to the left of the closing tag.

This feels like it should work, so something must be wrong.  Shoot it
full of holes, boys.


> Further it should ignore any whitespace ";"s (and comments) that
> follow the terminator.  

I've seen no reason to allow a semicolon other than "why not".  Its a
special case which adds no syntax sugar and simply represents
unnecessary orthoginality.  It just lets you be sloppy.

Comments, too.  Since the here-doc tag is free-form, you can make it
anything you'd like.  Including a comment!

For example, why would this:

        print <<EOF;
    Foo
    EOF  # This is the end of the here-doc, my friends.

be any better than this?

        print <<THIS_IS_THE_END;
    Foo
    THIS_IS_THE_END

I can't think of much else I'd want to comment about the end of a
here-doc than "this is the end of the here-doc" which is about as
useful as "$i++ # add one to $i".


> Perl should also ignore whitespace between the << and
> the terminator.  

I'm worried this might cause here docs to look too much like left shift
operators.  And consider the following ambiguity.

    use constant BAR => 2;

    $foo << BAR;
Stuff
BAR

    print $foo << BAR;

The first is a here-doc.  The second is a left shift.  They look
veeery close.


> =head1 IMPLENTATION
> 
> This should be a relatively simple addition to perl 
> (I think just to scan_heredoc in toke.c + docs in perl5)

The disambiguation of a here-doc start from a binary left shift might
add serious complexity to th parser.


-- 

Michael G Schwern      http://www.pobox.com/~schwern/      [EMAIL PROTECTED]
Just Another Stupid Consultant                      Perl6 Kwalitee Ashuranse
"None of our men are "experts."... because no one ever considers
himself expert if he really knows his job."  
-- From Henry Ford Sr., "My Life and Work," p. 86 (1922): 

Reply via email to