[SVN] Revision 1085 (Perl)

Eric Hsu textmate at betterfilecabinet.com
Fri May 27 00:02:24 UTC 2005

# This check-in includes near-full support for Perl here-doc strings. There are some cases involving stacked here-docs that I can't get right. But this should work for 90% of the cases, including ones where the terminating string is quoted in various ways (",',`) and thanks to the cool new regexp engine, we actually can check for matching quotes!

# This check-in comment is the actual test document I used. I can't get the last here-doc to work right.

# By the way, using 'swallow="";' is an efficient way to crash Textmate utterly.  

# This is from Perl in a Nutshell, 4.2.3. Here Documents

# A line-oriented form of quoting is based on the Unix shell "here-document" syntax. Following a <<, you specify a string to terminate the quoted material, and all lines following the current line down to the terminating string are the value of the item. This is of particular importance if you're trying to print something like HTML that would be cleaner to print as a chunk instead of as individual lines. For example:

#!/usr/local/bin/perl -w

my $Price = 'right';

print <<"EOF";
The price is $Price.
# The terminating string does not have to be quoted. For example, the previous example could have been written as:

#!/usr/local/bin/perl -w

my $Price = 'right';

print <<EOF;
The price is $Price.
# You can assign here documents to a string:

my $assign_this_heredoc =<< "EOS";
This string is assigned to $whatever.

# You can use a here document to execute commands:

#!/usr/local/bin/perl -w

print <<`CMD`; #dklksdjfsf sdf lkjsldf k
ls -l

# One caveat about here documents: you may have noticed in each of these examples that the quoted text is always left-justified. That's because any whitespace used for indentation will be included in the string. For example:

#!/usr/local/bin/perl -w

print <<'    INDENTED';
    Same old, same old.

# Although you can use a trick of including whitespace in the terminating tag to keep it indented (as we did here), the string itself will have the whitespace embedded—in this case, it will be Same old, same old..

# You can stack here documents:

#!/usr/local/bin/perl -w

print <<"joe", <<"momma"; # You can stack them
I said foo.
I said bar.

# No string here!

U   trunk/Bundles/Perl.tmbundle/Syntaxes/Perl.plist

More information about the textmate-dev mailing list