http://qs321.pair.com?node_id=90272

Today in the Chatterbox, maddfisherman had some questions about the heredoc quoting mechanism, and OeufMayo and i started answering him, and brought up some things that tinman didn't know, and that brought up stuff none of us knew, so we ran some test scripts and found some interesting things.

first, some things i did know:

#!/usr/bin/perl -w use strict; my $foo = 'date'; print <<'SINGLE'; $foo SINGLE print <<"DOUBLE"; $foo DOUBLE print <<`BACK`; $foo BACK print <<IMPLIED; $foo IMPLIED
as the experienced heredoc user should know, this prints something like
$foo date Wed Jun 20 15:33:51 PDT 2001 date
Note that with no quotes, double quote interpolation is implied. (note, too, that your date probaby differs from mine.)

but what if you want to use other quoting mechaisms? i wanted to put a big long list into a qw(), and i tried

my @list = <<qw(HERE); Foo Bar Baz HERE
but it can't find string terminator qw.
my @list = qw <<HERE;
can't find string terminator >.
my @list = qw(<< HERE); Foo Bar Baz HERE
did better, but only because i consider the runtime error Can't locate object method "Baz" via package "HERE" at everywhere.pl line 23. to be better than not compiling. next step? well, this won't work:
my $bar = <<HERE; Foo Bar Baz HERE my @list = qw($bar);
because the $bar in qw() is not interpolated. this brings up the interesting point of how qw works. further tests seem to indicate that all the quoting functions (q, qq, qr, qw, and qx currently, and i think we get more in perl6) are hard to use with heredocs. in fact, aside from trivial cases, they seem to be hard to use, until you realize that they are operators and not functions. which brings up more questions, like "can we get at the underlying functions?" and "if so, how?" things along those lines.

so, uh, perhaps a heredoc tutorial and a quoters tutorial would be in order.

.

thanks to maddfisherman, OeufMayo, myocom, and others in the chatterbox for their assistance.

update: fixed some links. and no, CheeseLord i can't think of any specific reason to do it with qw//, but with some of the forthcoming quoting operators, maybe.

update 2: fixed IMPLIED as implied by Particle. bad copying on my part.

.